# how to test the number of arguments passed to the function

**URL:** <https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [February 18, 2011, 3:04pm UTC](https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010 "2011-02-18T15:04:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [February 18, 2011, 3:04pm UTC](https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010/1 "2011-02-18T15:04:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aaron\_Davies](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Aaron\_Davies](https://forum.kx.com/u/Aaron_Davies)\
**Post date:** [February 19, 2011, 1:44am UTC](https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010/2 "2011-02-19T01:44:00Z")

</div>



---

<div class="post-metadata">

**Author:** ![Type-nickname-h1](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@Type-nickname-h1](https://forum.kx.com/u/Type-nickname-h1)\
**Post date:** [February 19, 2011, 8:12pm UTC](https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010/3 "2011-02-19T20:12:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aaron\_Davies](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Aaron\_Davies](https://forum.kx.com/u/Aaron_Davies)\
**Post date:** [February 20, 2011, 3:55am UTC](https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010/4 "2011-02-20T03:55:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [February 21, 2011, 10:59am UTC](https://forum.kx.com/t/how-to-test-the-number-of-arguments-passed-to-the-function/7010/5 "2011-02-21T10:59:00Z")

</div>

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…\>
