I found a problem running example from q function reference. Here is
from the reference
==============================================================================================
q)u:(“abcde”;10 2 -6;(2 3;`ab))
q)u?10 2 -6
1
q)u?“abcde”
0
However, if the right argument is a general list then items of the
left argument are matched with items of the right argument. For
example,
q)u?(2 3;ab) 3 3 In this case Find matches items of the left argument with 2 3 and ab , not (2 3;ab). In order to find (2 3;ab) it must be an item of
a list, as follows.
q)u?enlist(2 3;`ab)
2
I tried the example in kdb with version:
KDB+ 2.4 2008.03.31 Copyright (C) 1993-2008 Kx Systems
q)u?enlist(2 3;`ab) / still gives 3 3 instead of 2
3 3
? is rank sensitive; x?y can’t deal with mixed rank x.
if rank x is n then x?y looks for objects of rank n-1.
e.g.
2 3?2 3#til 6 / looks for rank 0 objects
(0 1 2;4 5)?2 3#til 6 / looks for rank 1 objects
Thanks, Chuck.On Sep 21, 10:33?am, Charles Skelton <char…> wrote:> Documentation error>> ? is rank sensitive; x?y can’t deal with mixed rank x.> if rank x is n then x?y looks for objects of rank n-1.> e.g.> 2 3?2 3#til 6 ?/ looks for rank 0 objects> (0 1 2;4 5)?2 3#til 6 / looks for rank 1 objects>> For the case you mention, a solution is>> q)f:{where x~:y}> q)f[u;(2 3;ab)]> ,2>>>>>>>> On Wed, Sep 21, 2011 at 4:22 PM, dbtouch <dbto...> wrote:> > Hi, KDB Folks>> > I found a problem running example from q function reference. Here is> > from the reference>> > =========================================================================== ===================> > q)u:("abcde";10 2 -6;(2 3;ab))> > q)u?10 2 -6> > 1> > q)u?“abcde”> > 0> > However, if the right argument is a general list then items of the> > left argument are matched with items of the right argument. For> > example,>> > q)u?(2 3;ab)> > 3 3> > In this case Find matches items of the left argument with 2 3 and> > ab , not (2 3;ab). In order to find (2 3;ab) it must be an item of> > a list, as follows.>> > q)u?enlist(2 3;ab)> > 2>> > =========================================================================== ===================>> > I tried the example in kdb with version:> > KDB+ 2.4 2008.03.31 Copyright (C) 1993-2008 Kx Systems>> > q)u?enlist(2 3;ab) / still gives 3 3 instead of 2> > 3 3>> > Is it a reference error or KDB bug?>> > Thanks>> > –> >
Hi, ChuckI ran the function you gave and did not get 2q)f:{where x~\:y}q)f(u;(2 3;ab)){where x~:y}[((“abcde”;10 2 -6;(2 3;ab));(2 3;ab))]q)res:f(u;(2 3;ab))q)res{where x~\:y}[(("abcde";10 2 -6;(2 3;ab));(2 3;ab))]q)u"abcde"10 2 -6Could you take a look?On Sep 21, 10:33?am, Charles Skelton <char...> wrote:> Documentation error>> ? is rank sensitive; x?y can't deal with mixed rank x.> if rank x is n then x?y looks for objects of rank n-1.> e.g.> 2 3?2 3#til 6 ?/ looks for rank 0 objects> (0 1 2;4 5)?2 3#til 6 / looks for rank 1 objects>> For the case you mention, a solution is>> q)f:{where x~\:y}> q)f[u;(2 3;ab)]> ,2>>>>>>>> On Wed, Sep 21, 2011 at 4:22 PM, dbtouch <dbto…> wrote:> > Hi, KDB Folks>> > I found a problem running example from q function reference. Here is> > from the reference>> > =========================================================================== ===================> > q)u:(“abcde”;10 2 -6;(2 3;ab))> > q)u?10 2 -6> > 1> > q)u?"abcde"> > 0> > However, if the right argument is a general list then items of the> > left argument are matched with items of the right argument. For> > example,>> > q)u?(2 3;ab)> > 3 3> > In this case Find matches items of the left argument with 2 3 and> > ab , not (2 3;ab). In order to find (2 3;ab) it must be an item of> > a list, as follows.>> > q)u?enlist(2 3;ab)> > 2>> > =========================================================================== ===================>> > I tried the example in kdb with version:> > KDB+ 2.4 2008.03.31 Copyright (C) 1993-2008 Kx Systems>> > q)u?enlist(2 3;`ab) / still gives 3 3 instead of 2> > 3 3>> > Is it a reference error or KDB bug?>> > Thanks>> > –> >
Oops…Thanks, Chuck.On Sep 21, 10:55?am, Charles Skelton <char…> wrote:> pay attention to brackets - () is not the same as >> q)u:(“abcde”;10 2 -6;(2 3;ab))> q)f:{where x~\:y}> q)f[u;(2 3;ab)]> ,2>>>>>>>> On Wed, Sep 21, 2011 at 4:49 PM, dbtouch <dbto…> wrote:>> > I ran the function you gave and did not get 2>> > q)f:{where x~\:y}> > q)f(u;(2 3;ab))> > {where x~:y}[((“abcde”;10 2 -6;(2 3;ab));(2 3;ab))]> > q)res:f(u;(2 3;ab))> > q)res> > {where x~\:y}[(("abcde";10 2 -6;(2 3;ab));(2 3;ab))]> > q)u> > "abcde"> > 10 2 -6>> > Could you take a look?>> > On Sep 21, 10:33 am, Charles Skelton <char...> wrote:> > > Documentation error>> > > ? is rank sensitive; x?y can't deal with mixed rank x.> > > if rank x is n then x?y looks for objects of rank n-1.> > > e.g.> > > 2 3?2 3#til 6 ?/ looks for rank 0 objects> > > (0 1 2;4 5)?2 3#til 6 / looks for rank 1 objects>> > > For the case you mention, a solution is>> > > q)f:{where x~\:y}> > > q)f[u;(2 3;ab)]> > > ,2>> > > On Wed, Sep 21, 2011 at 4:22 PM, dbtouch <dbto…> wrote:> > > > Hi, KDB Folks>> > > > I found a problem running example from q function reference. Here is> > > > from the reference>> > ===========================================================================> > ===================> > > > q)u:(“abcde”;10 2 -6;(2 3;ab))> > > > q)u?10 2 -6> > > > 1> > > > q)u?"abcde"> > > > 0> > > > However, if the right argument is a general list then items of the> > > > left argument are matched with items of the right argument. For> > > > example,>> > > > q)u?(2 3;ab)> > > > 3 3> > > > In this case Find matches items of the left argument with 2 3 and> > > > ab , not (2 3;ab). In order to find (2 3;ab) it must be an item of> > > > a list, as follows.>> > > > q)u?enlist(2 3;ab)> > > > 2>> > ===========================================================================> > ===================>> > > > I tried the example in kdb with version:> > > > KDB+ 2.4 2008.03.31 Copyright (C) 1993-2008 Kx Systems>> > > > q)u?enlist(2 3;`ab) / still gives 3 3 instead of 2> > > > 3 3>> > > > Is it a reference error or KDB bug?>> > > > Thanks</dbto…></char…></dbto…></char…>