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

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

From: tim-johnsons::web::com at: 7-May-2007 8:22

On Monday 07 May 2007 10:52, Gabriele Santilli wrote:
> > 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. :)
Thanks Gabriele. That is the elegant way to do it as stand-alone code. The function type I am referring to will be used as part of an automatically generated code set. I thought about using the "unset" method to cut down on "clutter" if visual expection was done. Example: [eval [prn "total_charge" 0 ]] ^ ^ function | arbitrary marker. Just means "'do the following block" [literal "just a string"] ^ | arbitrary marker. Just means use the following string as-is. [eval [prn ["total_charge" 0] ]] ;; Gabriele's method. I like your method better for the coding of the function itself. cheers tim -- Tim Johnson <tim-johnsons-web.com> Palmer, Alaska, USA