Hi all,is there a way in q to test the number of arguments passed to thefunction:Consider the following task:plotx:{ ({date$x}each til count x;x) };plotxy:{ ([]{
date$x} each y;x) };plot: choose plotx if one argument is passed, if not choose plotxy.I know that i can use count count the numbers of arguments. Perhapsthere is a more elegant solution.Regards,Kim
KDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systemsl32/ 2()core 1979MB orib octisys 127.0.1.1 PLAY 2011.05.17q)g:('[{-1"got ",string count x};plist])q)g[“hello”]got 1-1q)g[“hello”;“world”]got 2-1q)g[“hello”;“world”;(1;2;3;4)]got 3-1Though I have no idea where/if this is documented.
On Feb 19, 2011, at 3:12 PM, Type-nickname-here wrote:
> KDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systems
> l32/ 2()core 1979MB orib octisys 127.0.1.1 PLAY 2011.05.17
>
> q)g:('[{-1"got ",string count x};plist])
> q)g[“hello”]
> got 1
> -1
> q)g[“hello”;“world”]
> got 2
> -1
> q)g[“hello”;“world”;(1;2;3;4)]
> got 3
> -1
>
> Though I have no idea where/if this is documented.
yeah, that’s not documented very well, if at all
plist returns a list (or vector) of its arguments, and is the only
(afaik) completely variadic function in q
so composing it with monadics makes them variadic too
Hi i.like.privacy,Thx for the hint. I will try to make use of it.Regards,KimOn 19 Feb., 21:12, Type-nickname-here <i.like.privacy…>wrote:> KDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systems> l32/ 2()core 1979MB orib octisys 127.0.1.1 PLAY 2011.05.17>> q)g:('[{-1"got ",string count x};plist])> q)g[“hello”]> got 1> -1> q)g[“hello”;“world”]> got 2> -1> q)g[“hello”;“world”;(1;2;3;4)]> got 3> -1>> Though I have no idea where/if this is documented.</i.like.privacy…>