ilog rule project reference and common variables - ilog

I am trying to create a rule project that will be used by few other rule projects.
The WODM document only mentions that it makes the application modular.
Rule project A references Rule Project B. B is new and has no rules written so far.
My question is -
- The rule parameters are common for A and B. When I provided reference, I got 'unambigous parameter' error. The error went off when I removed the parameters from B. Same is the case with local variables.
If this is how the setup needs to be done, how are these variables visible to B? If I add the reference to A, as expected, I get cyclic reference error. Can I change the preference to ignore this error? Is there any other way?
Thanks

Since the Rule Project A references Rule Project B, can you have the rule parameters from A and have in B.
Also, it all depends on how you are planning/designing these rule projects to be used in the applications, like the dependencies, independent calls to the rule project A or B, etc.

Related

Using CompilerMessageAttribute to produce a compiler error, but only in other assemblies

I have a union type that has a single, empty case.
type Default =
| Default
This type has a purpose, but it's not meant to be visible or usable.
Unfortunately, I have to use it in an inline function that does need to be visible. This prevents me from making the type or the case private.
The solution I came up with is using the CompilerMessageAttribute on it to signal an error whenever it's used. This would be fine, but now I can't compile my own assembly because IT uses it.
Is there a way to signal an error only when it's used by an assembly that references my assembly?
Let me reiterate the requirements to make sure I understand them:
The type needs to be public, so that that other assemblies can reference it implicitly via inline.
But if other assemblies reference it explicitly, then that is an error.
I don't know of any way of doing this using standard tooling.
I can see two possible solutions.
If only one calling assembly needs to use the inline function, what about making the type internal and then have the calling assembly be a friend assembly, using the InternalsVisibleToAttribute.
The only other alternative I can think of is security by obscurity. Hide the type in some awkwardly named module and require module qualification. This will stop accidental use of the type, if nothing else.
You could even add a build step to check that no source code references the module name.
[<RequireQualifiedAccessAttribute>]
module ``Dont Use This`` =
type Default =
| Default
let x = ``Dont Use This``.Default
And yes, it's very kludgy.

Dependency injection and state setup

I'd like to ask who is responsible for setting up the injected dependency's state?
For e.g when class A depends on class B, is instance A's responsibility to setup instance B or should it be done somewhere else? Why?
My questions is much more a general one, but I put the concrete situation here:
I have a Context class which handles interactions and states made to a given chart, e.g. you can switch between two series. However this class is also setting up chart's look and displayed data with by delegating them to other (injected) classes. Currently the Context constructor sets up its dependencies state based on its constructor parameters (e.g.: highlight one point on the chart, telling which series to display, etc). I'm not sure that this design is good and would like to get a deeper understanding about the right way. The programming language is Javascript (if it's matters).
Thanks,
Peter
when class A depends on class B, is instance A's responsibility to setup instance B or should it be done somewhere else?
If A would be responsibly of setting up B, this would make A violate the Dependency Inversion Principle (DIP) that says:
High-level modules should not depend on low-level modules. Both should
depend on abstractions.
The DIP is the driving force behind the Dependency Injection pattern.
But if A can't be responsible of creating B, who is? The answer to this question is: The Composition Root:
A Composition Root is a (preferably) unique location in an application
where modules are composed together.
Using a Composition Root is the only way that you can keep both A and B (and everything else in the graph) free from having a dependency on a different module.

cannot traverse the nodes of an AST, while assigning each node an ID

This is more a simple personal attempt to understand what goes on inside Rascal. There must be better (if not already supported) solution.
Here's the code:
fileLoad = |home:///PHPAnalysis/systems/ApilTestScripts/simple1.php|;
fileAST=loadPHPFile(fileLoad,true,false);
//assign a simple id to each node
public map[value,int] assignID12(node N)
{
myID=();
visit(N)
{
case node M:
{
name=getName(M);
myID[name] =999;
}
}
return myID;
}
ids=assignID12(fileAST);
gives me
|stdin:///|(92,4,<1,92>,<1,96>): Expected str, but got value
loadPHPFile returns a node of type: list[Stmt], where each Stmt is one of the many types of statements that could occur in a program (PHP, in my case). Without going into why I'd do this, why doesn't the above code work? Especially frustrating because a very simple example is worked out in the online documentation. See: http://tutor.rascal-mpl.org/Recipes/Basic/Basic.html#/Recipes/Common/CountConstructors/CountConstructors.html
I started a new console, and it seems to work. Of course, I changed the return type from map[value,int] to map[str,int] as it was originally in the example.
The problem I was having was that I may have erroneously defined the function previously. While I quickly fixed an apparent problem, it kept giving me errors. I realized that in Rascal, when you've started a console and imported certain definitions, it (seems)is impossible to overwrite those definitions. The interpreter keeps making reference to the very first definition that you provided. This could just be the interpreter performing a type-check, and preventing unintentional and/or incompatible assignments further down the road. That makes sense for variables (in the typical program sense), but it doesn't seem like the best idea to enforce that on functions (or methods). I feel it becomes cumbersome, because a user typically has to undergo some iterations before he/she is satisfied with a function definition. Just my opinion though...
Most likely you already had the name ids in scope as having type map[str,int], which would be the direct source of the error. You can look in script https://github.com/cwi-swat/php-analysis/blob/master/src/lang/php/analysis/cfg/LabelState.rsc at the function labelScript to see how this is done in PHP AiR (so you don't need to write this code yourself). What this will give you is a script where all the expressions and statements have an assigned ID, as well as the label state, which just keeps track of some info used in this labeling operation (mainly the counter to generate a unique ID).
As for the earlier response, the best thing to do is to give your definitions in modules which you can import. If you do that, any changes to types, etc will be picked up (automatically if the module is already imported, since Rascal will reimport the module for you if it has changed, or when you next import the module). However, if you define something directly in the console, this won't happen. Think of the console as one large module that you keep adding to. Since we can have overloads of functions, if you define the function again you are really defining a new alternative to the function, but this may not work like you expect.

Ninject 2.2 multiple bindings

I recently updated ASP.NET MVC 3 app to Ninject 2.2.
Previously I had the following interface to implementation binding in my main app:
Bind(typeof(IMyInterface<>)).To(typeof(MyImplementation<>)).InRequestScope();
In addition, I had the following in a different assembly that was being loaded by my main app:
var arg = new ConstructorArgument("info", "something");
Bind<IMyInterface<MyClass>>().To<MyImplementation<BlogComment>>().WithParameter(arg);
This worked fine previously and the more specific implementation (the one with the argument) was being recognized. However, when I upgraded to Ninject 2.2, I received the following error:
Error activating IMyInterface{MyClass}
More than one matching bindings are available.
Activation path:
2) Injection of dependency IMyInterface{MyClass} into parameter myParam of constructor of type SomeOtherClass
1) Request for IMyInterface
Suggestions:
1) Ensure that you have defined a binding for IMyInterface{MyClass} only once.
What change was made from 2.0 to 2.2 that is causing this and is there a work around?
Ninject 2.2 ensures that only one matching bindings exists when resolving instances. 2.0 returned an instance of the first matching binding ignoring that there are others. But having multiple bindings if only one is requested reflects a bad configuration and can lead to hard to detect unintended behaviors.
But I see that there should be the possibility to overrule open generic bindings with more specific ones. I'll definitely look into it and it will either be added to a bugfix release or the next major release.

What does the tick mark `1 in the file name mean within the ASP.NET MVC source code?

Looking in the ASP.NET MVC 2 source code there are several files in the System.Web.Mvc project that have an almost identically named file except for the `1 on the end of the file name.
For example, there is HtmlHelper.cs and HtmlHelper`1.cs. Another example is AjaxHelper.cs and AjaxHelper`1cs.
At first glance, the obvious answer is the `1 files contain the generic versions of their respective non-generic classes.
I'm wondering if there is something more to this naming convention though given that we have other files like ReaderWriterCache`2.cs which contains the ReaderWriterCache file that doesn't inherit from any type of non-generic base class.
Does anyone have a better idea on what the naming convention is used to denote?
The number at the end indicates the number of generic type parameters. So, ReaderWriterCacherequires'2 requires 2 type parameters, TKey and TValue. HtmlHelper'1 only requires 1.
Not sure if this is even relevant, but here's some code snippets from a project:
List<UserAction> myUserActionList;
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "List`1"; //ts.MappingName = myUserActionList.GetType().Name;
The last line contains a comment which could have replaced that line with no difference in behaviour.

Resources