Hi, KDB folksI am having difficulty understanding the exmple in 5.3.1 of Q languagereference manual:d:((1 2 3;4 5;6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20))How to evaluate d[0 2;;1 0] in more explicit way?Thanks,db
> d:((1 2 3;4 5;6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20))>> How to evaluate d[0 2;;1 0] in more explicit way?Your indexing expression is semantically equivalent to: d[0 2; ::; 10], with :: standing for the elided index. When d is a list, theelided index works like a universal quantifier for that level in thelist. Since all children of d in your example are lists of length 3,you could use d[0 1;0 1 2;1 0] as well. I don’t think there’s anequivalent non-elided expression if you had sublists of differinglengths.If d were a function (not a list), you’d get a projection back. Theprojection would be semantically equivalent to the lambda expression:{d[0 2;x;1 0]}q)d[0 2;;1 0]~d[0 2;::;1 0]1bq)d[0 2;;1 0]~d[0 2;0 1 2;1 0]1bq)f:{d[0 2;x;1 0]}q)d[0 2;;1 0]~f 0 1 2---------------------------------- off topic---------------------------------In playing with this, I found a couple of head scratchers. First, theparser seems to be doing something special with the elided indexsyntax. For instance, you get an error if you try to parse a stringcontaining your original expression:q)parse “d[0 2;;1 0]“k){$[(::)~x;””;`/:S[(.“\c”)-2 1;0j]x]}'type@`/:(“`d”;“0 2”;![-3;];“1 0”)q.Q))The other one is that calling the function f above without argumentsactually produces the result instead of returning a projection.q)f2 1 5 4 7 614 13 16 15 20 19Can one of the Q gods explain why f isn’t projected here?
i think it helps somewhat in understanding that :: is the identity function apart from being general null as well q)(::)1 2 31 2 3and more importantly (nice duality)q)1 2 3(::)1 2 3think of :: (or elided indices) in d[0 2;::;1 0] as give me all the data (just like All in Mathematica), not just for those indices i providedi hope this helps parse seems to work fine if you have a more complicated expressionq)parse"0+d[0 2;;1 0]“+0(d;0 2;::;1 0)and f[] is equivalent to f(::)regards, AttilaOn 2 Dec 2009, at 22:48, andyturk wrote:\>\> d:((1 2 3;4 5;6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20))\>\> How to evaluate d[0 2;;1 0] in more explicit way?\> \> Your indexing expression is semantically equivalent to: d[0 2; ::; 1\> 0], with :: standing for the elided index. When d is a list, the\> elided index works like a universal quantifier for that level in the\> list. Since all children of d in your example are lists of length 3,\> you could use d[0 1;0 1 2;1 0] as well. I don't think there's an\> equivalent non-elided expression if you had sublists of differing\> lengths.\> \> If d were a function (not a list), you'd get a projection back. The\> projection would be semantically equivalent to the lambda expression:\> {[x]d[0 2;x;1 0]}\> \> q)d[0 2;;1 0]~d[0 2;::;1 0]\> 1b\> q)d[0 2;;1 0]~d[0 2;0 1 2;1 0]\> 1b\> q)f:{[x]d[0 2;x;1 0]}\> q)d[0 2;;1 0]~f 0 1 2\> \> ---------------------------------- off topic\> ---------------------------------\> \> In playing with this, I found a couple of head scratchers. First, the\> parser seems to be doing something special with the elided index\> syntax. For instance, you get an error if you try to parse a string\> containing your original expression:\> \> q)parse "d[0 2;;1 0]"\> k){$[(::)~x;"";
/:S[(.”\c")-2 1;0j]x]}> 'type> @> /:\> ("
d";“0 2”;![-3;];“1 0”)> q.Q))> > The other one is that calling the function f above without arguments> actually produces the result instead of returning a projection.> > q)f> > 2 1 5 4 7 6> 14 13 16 15 20 19> > Can one of the Q gods explain why f isn’t projected here?> > –> > Submitted via Google Groups
Thanks, everyone for answering my question.I have another question related to this: d 1 2 3 gives(8 9;10;11 12)(13 14;15 16 17 18;19 20)(int$();
int$())Is (int$();
int$()) a general value for NULL int list? Why it is not(int$();
int$();int$())?On Dec 3, 4:19?am, Attila Vrabecz <attila.vrab...> wrote:> i think it helps somewhat in understanding that :: is the identity function> apart from being general null as well> q)(::)1 2 3> 1 2 3> and more importantly (nice duality)> q)1 2 3(::)> 1 2 3>> think of :: (or elided indices) in d[0 2;::;1 0] as give me all the data (just like All in Mathematica), not just for those indices i provided> i hope this helps ?>> parse seems to work fine if you have a more complicated expression> q)parse"0+d[0 2;;1 0]"> +> 0> (
d;0 2;::;1 0)>> and f is equivalent to f(::)>> regards,> ? Attila> On 2 Dec 2009, at 22:48, andyturk wrote:>>>> >> d:((1 2 3;4 5;6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20))> >> How to evaluate d[0 2;;1 0] in more explicit way?>> > Your indexing expression is semantically equivalent to: d[0 2; ::; 1> > 0], with :: standing for the elided index. When d is a list, the> > elided index works like a universal quantifier for that level in the> > list. Since all children of d in your example are lists of length 3,> > you could use d[0 1;0 1 2;1 0] as well. I don’t think there’s an> > equivalent non-elided expression if you had sublists of differing> > lengths.>> > If d were a function (not a list), you’d get a projection back. The> > projection would be semantically equivalent to the lambda expression:> > {d[0 2;x;1 0]}>> > q)d[0 2;;1 0]~d[0 2;::;1 0]> > 1b> > q)d[0 2;;1 0]~d[0 2;0 1 2;1 0]> > 1b> > q)f:{d[0 2;x;1 0]}> > q)d[0 2;;1 0]~f 0 1 2>> > ---------------------------------- off topic> > --------------------------------->> > In playing with this, I found a couple of head scratchers. First, the> > parser seems to be doing something special with the elided index> > syntax. For instance, you get an error if you try to parse a string> > containing your original expression:>> > q)parse “d[0 2;;1 0]”> > k){$[(::)~x;“”;`/:S[(.“\c”)-2 1;0j]x]}> > 'type> > @> > `/:> > (“`d”;“0 2”;![-3;];“1 0”)> > q.Q))>> > The other one is that calling the function f above without arguments> > actually produces the result instead of returning a projection.>> > q)f> > > > 2 1 ? 5 4 ? 7 6> > 14 13 16 15 20 19>> > Can one of the Q gods explain why f isn’t projected here?>> > –>> >
Submitted via Google Groups</attila.vrab…>
it is what you would expectq)0N!d 1 2 3 ((8 9;10;11 12);(13 14;15 16 17 18;19 20);(int$();
int$();int$()))maybe you have modified your dRegards, AttilaOn 4 Dec 2009, at 01:54, dbtouch wrote:\> Thanks, everyone for answering my question.\> \> I have another question related to this: d 1 2 3 gives\> \> (8 9;10;11 12)\> (13 14;15 16 17 18;19 20)\> (
int$();int$())\> \> Is (
int$();int$()) a general value for NULL int list? Why it is not\> (
int$();int$();
int$())?> > On Dec 3, 4:19 am, Attila Vrabecz <attila.vrab…> wrote:>> i think it helps somewhat in understanding that :: is the identity function>> apart from being general null as well>> q)(::)1 2 3>> 1 2 3>> and more importantly (nice duality)>> q)1 2 3(::)>> 1 2 3>> >> think of :: (or elided indices) in d[0 2;::;1 0] as give me all the data (just like All in Mathematica), not just for those indices i provided>> i hope this helps >> >> parse seems to work fine if you have a more complicated expression>> q)parse"0+d[0 2;;1 0]“>> +>> 0>> (d;0 2;::;1 0)>> >> and f[] is equivalent to f(::)>> >> regards,>> Attila>> On 2 Dec 2009, at 22:48, andyturk wrote:>> >> >> >>>> d:((1 2 3;4 5;6 7);(8 9;10;11 12);(13 14;15 16 17 18;19 20))>>>> How to evaluate d[0 2;;1 0] in more explicit way?>> >>> Your indexing expression is semantically equivalent to: d[0 2; ::; 1>>> 0], with :: standing for the elided index. When d is a list, the>>> elided index works like a universal quantifier for that level in the>>> list. Since all children of d in your example are lists of length 3,>>> you could use d[0 1;0 1 2;1 0] as well. I don't think there's an>>> equivalent non-elided expression if you had sublists of differing>>> lengths.>> >>> If d were a function (not a list), you'd get a projection back. The>>> projection would be semantically equivalent to the lambda expression:>>> {[x]d[0 2;x;1 0]}>> >>> q)d[0 2;;1 0]~d[0 2;::;1 0]>>> 1b>>> q)d[0 2;;1 0]~d[0 2;0 1 2;1 0]>>> 1b>>> q)f:{[x]d[0 2;x;1 0]}>>> q)d[0 2;;1 0]~f 0 1 2>> >>> ---------------------------------- off topic>>> --------------------------------->> >>> In playing with this, I found a couple of head scratchers. First, the>>> parser seems to be doing something special with the elided index>>> syntax. For instance, you get an error if you try to parse a string>>> containing your original expression:>> >>> q)parse "d[0 2;;1 0]">>> k){$[(::)~x;"";
/:S[(.”\c")-2 1;0j]x]}>>> 'type>>> @>>> /:>>> ("
d";“0 2”;![-3;];“1 0”)>>> q.Q))>> >>> The other one is that calling the function f above without arguments>>> actually produces the result instead of returning a projection.>> >>> q)f>>> >>> 2 1 5 4 7 6>>> 14 13 16 15 20 19>> >>> Can one of the Q gods explain why f isn’t projected here?>> >>> –>> >>>
Submitted via Google Groups</attila.vrab…>