Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: vargs function (or "r-expression)

From: santilli::gabriele::gmail::com at: 7-May-2007 12:52

2007/5/6, Tim Johnson <tim-johnsons-web.com>:
> 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]
You can also just call it with: (vargs "two" 3) (vargs "two" 3 "four") (vargs) etc. (More Lispy. ;) However, I don't think this is a great idea when you have many arguments, and it'll cause problems if you forget the parens. If you need variable nuber of arguments, the best way is: vargs: func [args [block!] /local a b c] [ set [a b c] reduce args ?? a ?? b ?? c ]
>> vargs []
a: none b: none c: none == none
>> vargs [1 2]
a: 1 b: 2 c: none == none
>> vargs [2 + 2 3]
a: 4 b: 3 c: none == none This is the starting point to make your ARGS block a dialect. :) HTH, Gabriele.