varargs in rebol?
[1/4] from: princepawn::mailandnews::com at: 31-Aug-2000 10:29
Is it possible to design a rebol function that takes a variable number of
arguments, ie:
va-func 1 2
va-func 1 2 3
va-func 1 2 3 4
What immediately comes to mind is to use a block for the varargs part of the
call, ie
va-func 1 [2]
va-func 1 [2 3]
va-func 1 [2 3 4]
But I thought I would just jog the brains of those around me :-)
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer]
free-email: http://www.MailAndNews.com
free-usenet: http://www.mailAndNews.com
; all the above is real REBOL code, believe it or not.
[2/4] from: jelinem1:nationwide at: 31-Aug-2000 11:11
Passing in a block would probably be the best (most generic) solution. If
you have a fixed number of parameters that you could receive, but at times
you don't need to pass them all in, you could surround your parameters with
parenthesis (in the function call) then check for values of the dummy
parameters (inside the function) of unset!.
- Michael Jelinek
[princepawn--MailAndNews--com]@MailAndNews.com> on 08/31/2000 09:29:13 AM
From: [princepawn--MailAndNews--com]@MailAndNews.com on 08/31/2000 09:29 AM
Please respond to [list--rebol--com]
Sent by: Terrence Brannon <[princepawn--MailAndNews--com]>
To: [list--rebol--com]
cc:
Subject: [REBOL] varargs in rebol?
Is it possible to design a rebol function that takes a variable number of
arguments, ie:
va-func 1 2
va-func 1 2 3
va-func 1 2 3 4
What immediately comes to mind is to use a block for the varargs part of
the
call, ie
va-func 1 [2]
va-func 1 [2 3]
va-func 1 [2 3 4]
But I thought I would just jog the brains of those around me :-)
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer]
free-email: http://www.MailAndNews.com
free-usenet: http://www.mailAndNews.com
; all the above is real REBOL code, believe it or not.
[3/4] from: tim:johnsons-web at: 31-Aug-2000 10:03
Hi:
You wouldn't need to pass the number of args:
Just get the length of the block from within the function body
i.e:
test: func[args[block!] /local num-args]
[
num-args: length? args
print num-args
foreach arg args [print type? arg]
]
test ["one" 2 3:00]
After dealing with my own variable argument issues in C/C++, this is
so nice!
HTH
:) regards
Tim
[princepawn--MailAndNews--com] wrote:
[4/4] from: brian:hawley:bigfoot at: 31-Aug-2000 18:57
[princepawn--MailAndNews--com] wrote:
>Is it possible to design a rebol function that takes a variable number of
>arguments, ie:
>
>va-func 1 2
>va-func 1 2 3
>va-func 1 2 3 4
This method would break the REBOL syntax, which depends on
functions having a fixed number of arguments. This is so
that we don't need to put parentheses around argument lists.
>What immediately comes to mind is to use a block for the varargs part of the
>call, ie
>
>va-func 1 [2]
>va-func 1 [2 3]
>va-func 1 [2 3 4]
That's the way that standard functions in REBOL do it.
Take a look at the source to the join function for a way
to do argument lists that way.
Brian Hawley