Home › Forums › KX Academy › Why does this work: value each {x+y+z}[1;;],’enlist (2;enlist 3) › Re: Why does this work: value each {x+y+z}[1;;],’enlist (2;enlist 3)
-
Might be best to deal with this in pieces
q)(2;3)
2 3
q)(2;enlist 3)
2
,3Here, the enlist is to prevent 2 and 3 concatenating into a simple list of longs.
The difference in the final output is an extra level of enlisting:
q)value each{x+y+z}[1;;],’enlist(2;3)
,6
q)value each{x+y+z}[1;;],’enlist(2;enlist 3)
6
q)type value each{x+y+z}[1;;],’enlist(2;enlist 3)
0h
q)type value each{x+y+z}[1;;],’enlist(2;3)
7hWhy the other enlist?
q){x+y+z}[1;;],'(2;enlist 3)
{x+y+z}[1;;] 2
{x+y+z}[1;;] 3
q){x+y+z}[1;;],’enlist(2;enlist 3)
{x+y+z}[1;;] 2 ,3In the first example, each element of the right-hand list (2 and ,3) is joined to the projection, which results in two projections being returned.
With the enlist, the right-hand side is now a one-element list (the element being (2;,3)). This is joined to the projection.