I hadn’t intended for this to be so wordy - apologies.
Parsing…
the core grammar is: E:E;e|e e:nve|te| t:n|v v:tA|V n:t[E]|(E)|{E}|N
the relevant parts to adverb and application are:
v:tA (a verb is a term followed by an adverb.
n:t[E] (a term followed by a ‘[’)
- Why does this work?
{[x;y] x+y}/[1;2]
3
this parses as t[E] where t is a verb (tA) where the lambda is a term (t)
q)0N!parse"{[x;y] x+y}/[1;2]";
((/;{[x;y] x+y});1;2)
t is a verb that can accept one or two arguments. two arguments are provided as E (1 and 2) and is equivalent to the juxtapose
q)0N!parse"1{[x;y] x+y}/2";
((/;{[x;y] x+y});1;2)
note that the first arg in the call is the "x" argument (left) and the second is "y"
- And this does not.
0{[x;y] x+y}/[1;2]
this expression is equivalent to:
0 ( 1{[x;y] x+y}/2 )
q)0N!parse"0{[x;y] x+y}/[1;2]";
(0;((/;{[x;y] x+y});1;2))
that is, 0(6) - and the function “zero” does not like integers: http://code.kx.com/wiki/Reference/Zero
it can be thought that kdb+ evaluates from right to left of “right of left”, but it is actually the parsing rules that cause the right of left “evaluation”.
considering e:nve|te|e| and “1-2+3”. using nve: (1-“2+3”) -> (1-(2+“3”)) -> (1-(2+(3))) (last step by e:te|)
the actual tree is:
q)0N!parse"1-2+3";
(-;1;(+;2;3)) /verb followed by arguments - recursively evaluated
- And this does not.
0 {[x;y] x+y}/[1 2 3]
'type
we know that {[x;y] x+y}/[1 2 3] evaluates to 6. so the expression reduces to 0(6).
as soon as you use the n:t[E] syntax, the t expression becomes a noun and there is no way to pass an x/left argument to a noun by using juxtaposition (only verbs allow arguments to their left - oh, and an adverb takes a single term to it’s left)
- This does not work as well AND it produces different error message…
0 {[x;y] x+y}/ [1 2 3 4 5]
'length
this one seems to be a curiosity - 0 must have at least two constraints (type and length) and the length constraint isn’t violated until an integer argument exceeds 9. the length constraint is checked first and so when length constraint is violated… that’s my guess.