[REBOL] Re: variable number of arguments
From: al:bri:xtra at: 26-Nov-2000 16:18
Ladislav Mecir wrote:
> Andrew Martin wrote:
> > Graham Chiu wrote:
> > > Can a function have a variable number of arguments?
> > No. But you can simulate it, by using 'any-type! function specifiers and
passing unset! as arguments. Better is to use refinements.
> Yes, a function can have a variable number of arguments. Do is such a
function, as e.g. in:
> take-n: func [n /local spec] [
> spec: copy []
> for i 1 n 1 [
> append spec to word! append copy "a" to string! i
> ]
> func spec reduce [:reduce append reduce [to lit-word! append copy
take
to string! n] spec]
> ]
> do take-n 4 1 2 3 4
> == [take4 1 2 3 4]
>
> , where Do took 5 arguments.
Actually, 'do took only one argument, the value returned from 'take-n (which
had the argument "4"), which happened to be a function that is evaluated by
'do that could take the next four arguments "1 2 3 4".
So the answer to the question:
> Can a function have a variable number of arguments?
is still: No.
>> help do
USAGE:
DO value /args arg /next
DESCRIPTION:
Evaluates a block, file, URL, function, word, or any other value.
DO is a native value.
ARGUMENTS:
value -- Normally a file name, URL, or block (Type: any)
REFINEMENTS:
/args -- If value is a script, this will set its system/script/args
arg -- Args passed to a script. Normally a string. (Type: any)
/next -- Do next expression only. Return block with result and new
position.
Note that 'do only has one argument.
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/