Question1.
a: 1,2,3,4,5
b:1 2 3 4 5
c:(1;2;3;4;5)
What are the differences among them?
Question2.
What is
d:1;2;3;4;5
Question3.
aa:(4%0;-4%0;0;3)
bb:4%0, -4%0, 0, 3
What are the differences between them?
Question1.
a: 1,2,3,4,5
b:1 2 3 4 5
c:(1;2;3;4;5)
What are the differences among them?
Question2.
What is
d:1;2;3;4;5
Question3.
aa:(4%0;-4%0;0;3)
bb:4%0, -4%0, 0, 3
What are the differences between them?
In general, Q executes right-to-left<o:p></o:p>
<o:p> </o:p>
And you can use ~ to compare data structures.<o:p></o:p>
<o:p> </o:p>
Q1: no difference<o:p></o:p>
q)a: 1,2,3,4,5<o:p></o:p>
q)b:1 2 3 4 5<o:p></o:p>
q)c:(1;2;3;4;5)<o:p></o:p>
q)a~b<o:p></o:p>
1b<o:p></o:p>
q)a~c<o:p></o:p>
1b<o:p></o:p>
<o:p> </o:p>
1.a takes the atom 5 and prepends 4 to it resulting in a 2-element list. Then prepends 3 to that to get a 3 element list. Ad naseum<o:p></o:p>
1.b is shorthand for creating a list it only works for primitive non-mixed data types (like int lists below)<o:p></o:p>
1.c is the standard way to create a list and supports mixed data types for example (1;`; “”)<o:p></o:p>
<o:p> </o:p>
Q2: ; is used to separate statements. So it assigns 1 to d then runs 2 then 3 then 4 then 5. And since the last statement doesnt end in ; it prints the result (in this case 5)<o:p></o:p>
q)d:1;2;3;4;5<o:p></o:p>
5<o:p></o:p>
q)d<o:p></o:p>
1<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Q3:<o:p></o:p>
aa is creating a list with 4 elements as specified<o:p></o:p>
bb is creating a 4-element list but the elements are calculated in right-to left<o:p></o:p>
1) 0,0,3 creates a 3-element list<o:p></o:p>
2) -4% divides -4 by each item in (1) ie: returns a list (-4%0;-4%0;-4%3) = -0w -0w -1.3333<o:p></o:p>
3) 0, prepends 0 to (2). Since its a different data type (0 is int/long vs (2) which is a float list) you get a mixed list<o:p></o:p>
4) 4% divides 4 by each (3) ie: 0w -0 -0 -3 - since each element is now a float, its no longer a mixed list<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
From: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] On Behalf Of Yuxin Wei
Sent: Wednesday, August 5, 2015 8:10 AM
To: Kdb+ Personal Developers
Subject: [personal kdb+] New to KDB+, a entry question. Thanks for helping~<o:p></o:p>
<o:p> </o:p>
Question1.<o:p></o:p>
a: 1,2,3,4,5<o:p></o:p>
b:1 2 3 4 5<o:p></o:p>
c:(1;2;3;4;5)<o:p></o:p>
What are the differences among them?<o:p></o:p>
<o:p></o:p>
Question2.<o:p></o:p>
What is<o:p></o:p>
d:1;2;3;4;5<o:p></o:p>
<o:p> </o:p>
Question3.<o:p></o:p>
aa:(4%0;-4%0;0;3)<o:p></o:p>
bb:4%0, -4%0, 0, 3<o:p></o:p>
What are the differences between them?<o:p></o:p>
<o:p> </o:p>
–
Submitted via Google Groups
Thank you sooooo much, and this answer really helps me out perfectly!
And I come up with some questions as well. I will post it during day time.
Thank you again and have a nice day!