There are code snippets in this Spock wiki page that involve double right arrow operators (>>). For example:
setup:
subscriber.isAlive() >> true
So, what does the >> operator mean in this case? Thank you very much.
The right-shift (>>) operator defines the return value or behavior of a stubbed method. You can find more information under Stubbing in the reference documentation.
Related
If the raw SPARQL is rdfs:label "D (programming language)"#en, what would the hsparql syntax be?
I'm the maintainer of the hsparql DSL that you are having trouble with. A `simpleSelectWithLiteral' function has been added as an example:
https://github.com/robstewart57/hsparql/blob/master/tests/DBPedia.hs#L51
Does this solve your problem?
Looking at the DSL definition (line 251) on the HSparql Github page it looks like the following DSL rule applies:
instance TermLike ([Char], [Char]) where
varOrTerm (s, lang') = Term . RDFLiteralTerm $ RDFLiteralLang s lang'
It's been far too long since I wrote any Haskell so I'm not 100% certain what that translates to into a term but I assume it means use a tuple of two strings:
("value", "en")
The ternary operator has a shorthand version, i.e.
var = exp ?: exp2
I know it works in PHP. Other languages may have also picked it up. C# has similar functionality (for the context of this question) - ??.
When the condition passes, is the expression evaluated again, or is the result stored somewhere?
http://msdn.microsoft.com/en-us/library/ms173224.aspx
The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise it returns the right operand.
It is stored, not computed twice.
I have a mathematical expression in string form like:
string strExpression = "10+100+Math.Sin(90)";
I want to simply assign this expression (at run time) to a float variable (say result), so that it becomes the following code statement:
float result = 10+100+Math.Sin(90);
How can I do this?
You have to compile the expression within a syntactically correct code block. See http://devreminder.wordpress.com/net/net-framework-fundamentals/c-dynamic-math-expression-evaluation/ as an example.
Edit: Or alternatively write your own expression parser if the expression is going to be VERY simple (I wouldn't recommend this though)
You could use CS-Script to dynamically make a class with a method that you can run, if you don't want to write your own parser but rather use C# which you allready know..
It looks like the quasi quoter syntax has changed to now accept 4 arguments [ link ]. Has anyone used it yet? Thanks. I just want to build something really really simple, and the examples on the web won't work now.
Thanks in advance.
Each piece of the QuasiQuoter is just a function that takes a string (the content of the quasi-quote) and returns an appropriate value in the Q monad. If your quasiquoter doesn't support being used in some of those contexts, just return an error, e.g.:
someQuoter = QuasiQuoter { quoteType = const $ fail "type context unsupported"
, -- etc ...
}
The fail method calls report True, which produces a compiler error. This is pretty much the correct behavior.
Basically the changes are that you can now make quasiquoters for types and declarations (in addition to expressions and patterns).
It should be fine to set the type/declaration fields to error "This quasiquoter doesn't support splicing types/declarations" if you don't want to use them.
this is a fairly general question about whether people should be using brackets on method calls that take parameters or not.
i.e.
def someFunc(def p) {
...
}
then calling:
someFunc "abc"
vs...
someFunc("abc")
Is this just a question of consistency, or is there specific use cases for each?
It's primarily a question of consistency and readability, but note that Groovy won't always let you get away with omitting parentheses. For one, you can't omit parentheses in nested method calls:
def foo(n) { n }
println foo 1 // won't work
See the section entitled "Omitting parentheses" in the Style guide.
There's no specific case where you must remove them, you can always use them. It's just prettier to leave them out.
There are cases where you can't do that (where you could confuse a list/map parameter with a subscript operator for instance, nested calls, or when the statement is an assignment), but the general rule is that the outmost call can have no parenthesis if there is no ambiguity.
(deleted several lines, as I've just received notification that there is a post already with that info)
Groovy 1.8 will allow even more cases to omit parenthesis, you can check them out at
http://groovyconsole.appspot.com/script/355001
"an empty pair of parentheses is just useless syntactical noise!"
It seems to me that they are encouraging you to use parenthesis when they serve a purpose, but omit them when they are just "noise"