I am trying to append to a list inside an ADT as follows:
data MyADT = myadt(list[str] s);
m = myadt([]);
m.s += "test";
Which causes an error:
|prompt:///|(0,3,<1,0>,<1,3>): Expected list[str], but got str
?[Advice](http://tutor.rascal-mpl.org/Errors/Static/UnexpectedType/UnexpectedType.html)
Which seems like it should work because this works:
x = [];
x += "test";
Maybe I am missing something here?
Thanks!
Try this as a workaround:
rascal>m.s += ["test"];
MyADT: myadt(["test"])
It looks like a bug.
By the way we will remove the overloading of + to add both elements and concatenate lists and introduce a special operator for adding elements. It's confusing as it is now.
Related
Lets imagine this:
tree = {}
tree.__newindex = tree
num = math.random(5,5)
tree.meta = {}
What I want to do here is replace the 'meta' in tree.meta with the var num without it creating a new object just simply called num. That way I can do something like tree.01415 for example. Maybe there is some syntax that I can put in there to designate meta as the variable num?
If I understand you correctly, I think this is what you want:
tree[num] = "whatever"
Then whatever will be added to table tree with the value of num as its key.
Im trying to modify an epl by compiling it using the compileEPL() method and add more to e.g the where clause, however im havin trouble getting it work.
Lets say this is my epl:
select * from event where A = 1
and I want to add another where condition using the AND
and I compile the epl using compileEPL()
model.getWhereClause().getChildren().add(Expressions.and()
.add(Expressions.eq("B", )));
instead of giving me:
select * from event where A = 1 and B = 2 it just gives ..where A = 1 and not adding the new where clause.
Am I doing it wrong? The EPStatementObjectModel works fine for building an object EPL from scratch but not when compiling it and adding or modify it.
Does anyone know? Thanks.
The where-clause is rooted in an EQ since "A=1".
Expression equalsExpr = model.getWhereClause();
So construct an AND clause that holds the old EQ and the new EQ.
Expression and = Expressions.and().add(equalsExpr).add(Expressions.eq("B", ...));
Finally set the "and" as the new where-clause:
model.setWhereClause(and);
In summary, when modifying expressions to add "and": when old expression is not itself an AND you should build an AND node and add the old expression and new ones.
var openWos = #Model.MyMaintenanceDashboard.OpenWorkOrders;
Why is Visual Studio saying this is a syntax error? It runs fine, but what would the proper syntax be?
Update: OpenWos is a javascript variable
If this is a javascript code, then you need to quote it so that you do not get the 'syntax' error.
var openWos = '#Model.MyMaintenanceDashboard.OpenWorkOrders';
If you're setting a C# var, the correct syntax would be without the # in front of Model as you're already in a C# code block:
#{
var openWos = Model.MyMaintenanceDashboard.OpenWorkOrders;
}
Edit:
You've clarified that this is a JavaScript variable. There shouldn't be a syntax error at all, as this is valid Razor. There is a distinct difference between quoting the value as suggested by Stephen, and the code that you posted originally. The type of the JavaScript variable is a string when quoted instead of a number.
For example, including this in a page:
<script>
#{ int z = 10; }
var x = #z;
console.log(x);
console.log(typeof x);
var y = '#z';
console.log(y);
console.log(typeof y);
</script>
Results in the following being logged to the console:
10
number
10
string
And there is no syntax error reported using the variable #z in either instance.
I've found that you can get around this by adding zero:
var openWos = #Model.MyMaintenanceDashboard.OpenWorkOrders + 0;
I am new to F#, looking at it as an alternative to Matlab.
In reference to this question, how can I create an empty Serie and an empty Frame.
If I did not just miss it, why an empty Serie or Frame has not been designed in the library,
something like list.empty ?
Adding Frame.empty and Series.empty is a great suggestion. I think these should be in the library and I'm adding an issue to GitHub to make sure they get added.
In the meantime, you should be able to use something like this:
let empty : Series<int, float> = series []
let empty : Frame<int, string> = frame []
Note that I had to add type annotations - from my code snippet, the compiler cannot figure out what is the type of keys and values, so I had to explicitly specify that (but if you use the values as arguments to other functions, then this should not be needed).
The second line does not actually work in the current version, because of a bug (oops!) so you can use Frame.ofRows instead, which works fine:
let frame : Frame<int, string> = Frame.ofRows []
EDIT: The bug is now fixed in version 0.9.11-beta
A fairly basic question :
I would like to create a string initialized to a dynamically decided number of spaces in dart.
Here's something that worked :
String spaces(n) {
var result = new List<int>.filled(n+1,32);
return new String.fromCharCodes(result);
}
Is there a better way?
Well you can always fill the list with spaces and join them:
String spaces(n) => new List.filled(n + 1, ' ').join();
This seems quite concise and easy to interpret:
''.padRight(32, ' ')
Try it in DartPad