Variadic function: Difference between revisions

Content added Content deleted
(add BQN)
Line 641: Line 641:
=={{header|BQN}}==
=={{header|BQN}}==


All BQN functions can be variadic since they allow taking arbitrary length lists as arguments. A function can reject variadicity by defining a header to restrict the arguments to a specific length.
All BQN functions can be variadic since they allow taking lists of arbitrary length as arguments. A function can reject variadicity by defining a header to restrict the arguments to a specific length.


<lang bqn>Fun1 ← •Show¨
<lang bqn>Fun1 ← •Show¨
Line 647: Line 647:
Fun3 ← { 1=≠𝕩 ? •Show 𝕩; "too many arguments " ! 𝕩}</lang>
Fun3 ← { 1=≠𝕩 ? •Show 𝕩; "too many arguments " ! 𝕩}</lang>


Both Fun1 and Fun2 display all the values(arguments) of the lists given to them.
Both <tt>Fun1</tt> and <tt>Fun2</tt> display all the values (arguments) of the lists given to them.


Fun3 will throw an error is the argument given is not a length 1 list, or a non-list. Otherwise it will display its argument.
<tt>Fun3</tt> throws an error if the given argument is not a list of length 1 or not a list at all. Otherwise it displays its argument.


=={{header|C}}==
=={{header|C}}==