0

I learned from here that

[...] in a parse tree a variable is represented by a symbol containing its name. Thus to distinguish a symbol or a list of symbols from a variable it is necessary to enlist that expression.

Given that, why does below expression evaluate to (enlist;`a;`b) instead of just `a`b?

Asking because it seems enlist[`a;`b]~`a`b is true.

q)parse"(a;b)"
enlist
`a
`b
kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80

1 Answers1

1

I don't think you would ever want a parse tree to collapse two same-type values into a single uniform list, it would break the ability to eval the parse tree, e.g

q)a:1
q)b:1
q)
q)eval parse"(a;b)"
1 1
q)eval `a`b
'type
  [0]  eval `a`b
       ^

And secondly, (enlist;`a;`b) isn't the same as enlist[`a;`b] however the value of (enlist;`a;`b) is:

q)value[(enlist;`a;`b)]~enlist[`a;`b]
1b

So I guess it comes down to the nuanced differences between eval and value

terrylynch
  • 11,844
  • 13
  • 21
  • Thanks for the example Terry - I think that makes sense. Also feel this is related to my other question https://stackoverflow.com/questions/66304802/kdb-what-is-the-type-of-parsexy – kgf3JfUtW Feb 21 '21 at 17:03
  • Yep, related. Parse trees shouldn't be flattened – terrylynch Feb 21 '21 at 17:07