[REBOL] vargs function (or "r-expression)
From: tim-johnsons::web::com at: 6-May-2007 17:14
Hello Rebolers:
NOTE: 'vargs is a "C" term where variable arguments are used
and "r-expression" is a take on the lisp term: "s-expression".
In lisp, you can have variable argument lists and the function call
will be coded something like:
(func arg1 arg2 arg3)
I have a need for an "r-expression", that is - a class of functions that
will be evaluated by 'do as part of a block and can have 0 or more
arguments.
example:
do [vargs "two" 3]
do [vargs "two" 3 "four"]
do [vargs "two" 3 none "four"]
do[vargs]
I'm starting with this:
vargs: func[arg1[string! unset!] arg2[integer! unset!]
arg3[string! logic! none! unset!] arg4[string! logic! none! unset!]][
case/all[
value? 'arg1[?? arg1]
value? 'arg2[?? arg2]
value? 'arg3[?? arg3]
value? 'arg4[?? arg4]
]
]
This approach can work for me, I think, but I would welcome any comments,
observations or caveats.
thanks
tim
--
Tim Johnson <tim-johnsons-web.com>
Palmer, Alaska, USA