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

[REBOL] Re: variable number of arguments

From: lmecir:mbox:vol:cz at: 26-Nov-2000 3:08

> Graham 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. > > Andrew Martin
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. I call such functions VNA functions. The problem is, that there is currently no possibility to define VNA functions in Rebol, which is a pity, because it would allow us to create some nice dialects in Rebol (a message-passing dialect me and Elan tried to define some time ago can serve as an example). Fortunately, there is a way, how to emulate that. A function taking a block as its argument can behave as if the elements of the block were the arguments. As an example you can have a look at Any and All functions, or a lot of other nice examples. Regards Ladislav