why is this query working, and what does it do exactly ?

Hi all,can somebody explain why this query is working?a group a: til 8Regards,Kim

a is assigned to be an int list from 0-7, then ‘a group a’ maps each
element of a to its index in the list, try ‘a group reverse a:til 8’

Hi,

?

This query will create a dictionary where domain contains unique elements and range have elements list appears…

?

? a: til 8

? show a

? 0 1 2 3 4 5 6 7

?

q)a group b
0| 0
1| 1
2| 2
3| 3
4| 4
5| 5
6| 6
7| 7

?

q)c: 1 2 3 4 3 2 5 6
q)c group c
1| ,1
2| 2 2
3| 3 3
4| ,4
5| ,5
6| ,6

Regrads

Hemant

?

Thx for your explanation,

But why is this code executable?
Normally you cannot forward a map to a list

This code is not executable.
b a`b ! 1 2

But this code is executable:
a a`b ! 1 2

This is work as designed ?

Kim

>This code is not executable. 
>b a`b ! 1 2 

>But this code is executable: 

>a a`b ! 1 2 

Consider the latter to behave like 

q)a: 8?10       / use random vector so you can see the mapping better

q){a@x}ab!1,2           / value is used to index list a. the return value of f[dict] is the original keys and the returned list

a| 1
b| 9

This is different to the 

Cool,thx for your explaination.KimOn 10 Jul., 14:34, abcfoots <abcfo…> wrote:> >This code is not executable.> >b ab ! 1 2&gt; &gt;But this code is executable:&gt; &gt;a ab ! 1 2>> Consider the latter to behave like> q)a: 8?10 ? ? ? / use random vector so you can see the mapping better> q){a@x}ab!1,2 ? ? ? ? ? / value is used to index list a. the return value> of f[dict] is the original keys and the returned list> a| 1> b| 9>> This is different to the>>>> On Tuesday, July 10, 2012 7:27:03 AM UTC-4, kuentang wrote:>> > Thx for your explanation,>> > But why is this code executable?> > Normally you cannot forward a map to a list>> > This code is not executable.> > b ab ! 1 2&gt;&gt; &gt; But this code is executable:&gt; &gt; a ab ! 1 2>> > This is work as designed ?>> > Kim>> > On 10 Jul., 11:39, Kevin Smyth <kevin…> wrote:> > > a is assigned to be an int list from 0-7, then ‘a group a’ maps each> > > element of a to its index in the list, try ‘a group reverse a:til 8’>> > > On 10 July 2012 10:35, kuentang <kuent…> wrote:>> > > > Hi all,>> > > > can somebody explain why this query is working?>> > > > a group a: til 8>> > > > Regards,> > > > Kim>> > > > –> > > > You received this message because you are subscribed to the Google> > Groups “Kdb+ Personal Developers” group.> > > > To post to this group, send email to personal-kdbplus@googlegroups.com.>> > > > To unsubscribe from this group, send email to> > personal-kdbplus+unsubscribe@googlegroups.com.> > > > For more options, visit this group athttp://> > groups.google.com/group/personal-kdbplus?hl=en.- Zitierten Text> > ausblenden ->> > > - Zitierten Text anzeigen – Zitierten Text ausblenden ->> - Zitierten Text anzeigen -</kuent…></kevin…></abcfo…>

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1278)

> This code is not executable.
> b ab ! 1 2 \> \> But this code is executable: \> a ab ! 1 2

some forms of (sym@) mean “apply with left arg passed by name”

q)(a group a)~`a group a
1b
q)

if the object named does not exist, that’s an error

q)b group a
'b
q)`b group a
'b
q)

define it and it starts working

q)b:a
q)`b group a
0| 0
1| 1
2| 2
3| 3
4| 4
5| 5
6| 6
7| 7
q)

the result, btw, is a form of functional composition, and imao one of =
the more interesting bits of theory embedded in q:

considering a dict as a (partial) function from its keys to its values, =
then two dicts f and g st f’s value and g’s key are of the same type can =
be composed

q)f:abc!1 2 3 q)g:1 2 3!("foo";"bar";"quux") q)g f a| "foo" b| "bar" c| "quux" q)(g f)b
“bar”
q)

considering a vector as a dictionary from (0..n-1) to its values, then =
it can be composed with a dictionary of int value

q)v:42 137 23
q)h:abc!0 1 2 q)v h a| 42 b| 137 c| 23 q)(v h)b
137
q)

Cool,thx for the explanation.Btw is this feature somewhere documented ?KimAm 13.07.2012 04:52, schrieb Aaron Davies:>> This code is not executable.>> b ab ! 1 2\>\>\>\> But this code is executable:\>\> a ab ! 1 2> some forms of (sym@) mean “apply with left arg passed by name”>> q)(a group a)~a group a\> 1b\> q)\>\> if the object named does not exist, that's an error\>\> q)b group a\> 'b\> q)b group a> 'b> q)>> define it and it starts working>> q)b:a> q)b group a\> 0| 0\> 1| 1\> 2| 2\> 3| 3\> 4| 4\> 5| 5\> 6| 6\> 7| 7\> q)\>\> the result, btw, is a form of functional composition, and imao one of the more interesting bits of theory embedded in q:\>\> considering a dict as a (partial) function from its keys to its values, then two dicts f and g st f's value and g's key are of the same type can be composed\>\> q)f:abc!1 2 3> q)g:1 2 3!(“foo”;“bar”;“quux”)> q)g f> a| “foo”> b| “bar”> c| “quux”> q)(g f)b\> "bar"\> q)\>\> considering a vector as a dictionary from (0..n-1) to its values, then it can be composed with a dictionary of int value\>\> q)v:42 137 23\> q)h:abc!0 1 2> q)v h> a| 42> b| 137> c| 23> q)(v h)`b> 137> q)>

yes. here: http://kx.com/q/d/a/q1.htm#Functional Forms of Amend