If enlist function returns a list from its arg . Then why is the type of ret 0h ret:enlist 1 Similarly, type of d is 0h also. d:enlist 1! enlist 2
charset=“UTF-8”
X-Mailer: Microsoft Outlook 15.0
Thread-Index: AQFpNhFNkzlov0mZTJSmMKRLTy7EPZ6d+3IQ
Content-Language: en-us
I get very different answers to you:
q)type ret:enlist 1
7h
q)type d:enlist[1]! enlist 2
99h
The second statement doesn’t compile (! requires a list on both sides =
and due to right-to-left execution your leftmost enlist is applied after =
the 1!)
Can you please use a q prompt and copy/paste exactly what you see so we =
can help debug it?
Also, do you have either book (the recent Q Tips or the older Q For =
Mortals)? Both are excellent.
Regards,
David
-----Original Message-----
From: personal-kdbplus@googlegroups.com =
[mailto:personal-kdbplus@googlegroups.com] On Behalf Of analyst
Sent: Monday, July 6, 2015 2:30 PM
To: personal-kdbplus@googlegroups.com
Subject: [personal kdb+] dictionary defn from q mortals
If enlist function returns a list from its arg . Then why is the type of =
ret 0h
ret:enlist 1
Similarly, type of d is 0h also.
d:enlist 1! enlist 2
–=20
You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send =
an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.
0h means a generic list.
A symbol list will have 11h
q)type a
b`c
11h
A list with longs will have 7h
q)type 1 2 3 4
7h
A nested list with these two will have 0h.
q)type (a
b`c;5 6 7)
0h
A list of lists will give you 0h.
david, i think you ahve the query wrong. Please remove the square brackets. Then you will see you will get a type error. My question now is, why do we have to out the enlist inside () for it to work. Should the enlist not return a list. d:enlist 1! enlist 2 i am going by defns in q for mortals book online.
I mixed list will also be of type 0h.
q)type (1;`a)
0h
As David said both side of a dictionary must be lists.
q)enlist 1!enlist 2
'type
q)
q)(enlist 1)!enlist 2
1| 2
q)enlist[1]!enlist 2
1| 2
The latter two options are just two ways of producing the same thing and both as of type 99h.
In your question as two why
q)enlist 1!enlist 2
produces a type error it is due to q executing right to left. Essentially you are trying to bang an atom onto list. To ensure we make 1 into a list before attempting to create the dictionary we need the brackets.
charset=“UTF-8”
X-Mailer: Microsoft Outlook 15.0
Thread-Index: AQFpNhFNkzlov0mZTJSmMKRLTy7EPQE+eVGtAV+P5ReeiQ5doA==
Content-Language: en-us
Yes, the 'type error is because kdb+ evaluates right-to-left with no =
operator precedence. This part isn’t valid:
1! enlist 2
And the leftmost enlist isn’t even executed because of the error
! in this case needs both the left and right to be a list. So =
enlist[1]!enlist 2 fixes it as would (enlist 1)!enlist 2 because both =
force the enlist to happen before the !
Can you post the url?=20
-----Original Message-----
From: personal-kdbplus@googlegroups.com =
[mailto:personal-kdbplus@googlegroups.com] On Behalf Of analyst
Sent: Monday, July 6, 2015 2:46 PM
To: personal-kdbplus@googlegroups.com
Subject: RE: [personal kdb+] dictionary defn from q mortals
david,
i think you ahve the query wrong. Please remove the square brackets. =
Then you will see you will get a type error. My question now is, why do =
we have to out the enlist inside () for it to work. Should the enlist =
not return a list.
d:enlist 1! enlist 2
i am going by defns in q for mortals book online.=20
–=20
You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send =
an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.
q reads right to left. It will first do enlist 2 and then use ! operator to create a dictionary to 1 which won’t work because 1 needs to be enlisted. So, you need to put enlist 1 in parenthesis to tell q to enlist 1 first before applying ! operator.
q)(enlist 1) ! enlist 2
1| 2
q)type (enlist 1) ! enlist 2
99h
Guys, The question is why do I need to put enlist in paranthesis. My explanation is different than all yours but please let me know what you think. I feel like the answer is operator precedence. enlist 1!enlist 2 will actually enlist [1! enlist2] enlist [! [1; enlist2]] which will fail because ! requires a list. And 1 is not a list. Hence by adding ! we overrule operator precedence and it works. Doing enlist [1] calls the functional form of enlist and ends up doing the same thing ?
charset=“UTF-8”
X-Mailer: Microsoft Outlook 15.0
Thread-Index: AQFpNhFNkzlov0mZTJSmMKRLTy7EPQF4miToAUj0mlsBkptlMZ57ayDA
Content-Language: en-us
Hi,
> I feel like the answer is operator precedence.
Really?
>From me:
" Yes, the 'type error is because kdb+ evaluates right-to-left with no =
operator precedence. This part isn’t valid:
1! enlist 2
And the leftmost enlist isn’t even executed because of the error"
>From Himanshu:
" q reads right to left. It will first do enlist 2 and then use ! =
operator to create a dictionary to 1 which won’t work because 1 needs to =
be enlisted. So, you need to put enlist 1 in parenthesis"
>From Marcus:
" In your question as two why=20
q)enlist 1!enlist 2
produces a type error it is due to q executing right to left. =
Essentially you are trying to bang an atom onto list. To ensure we make =
1 into a list before attempting to create the dictionary we need the =
brackets."
If you expect to get future help from the list, please be so kind as to =
read the detailed responses you receive…
Regards,
David
-----Original Message-----
From: personal-kdbplus@googlegroups.com =
[mailto:personal-kdbplus@googlegroups.com] On Behalf Of analyst
Sent: Monday, July 6, 2015 3:23 PM
To: personal-kdbplus@googlegroups.com
Subject: Re: [personal kdb+] Re: dictionary defn from q mortals
Guys,
The question is why do I need to put enlist in paranthesis. My =
explanation is different than all yours but please let me know what you =
think.
I feel like the answer is operator precedence.
enlist 1!enlist 2 will actually
enlist [1! enlist2]
enlist [! [1; enlist2]]
which will fail because ! requires a list. And 1 is not a list. Hence =
by adding ! we overrule operator precedence and it works.
Doing enlist [1] calls the functional form of enlist and ends up doing =
the same thing ?
–=20
You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send =
an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.
David, Meant no dis respect. Appreciate all the help !