Concatenative language/Rest parametersStack languages do not immediately support variadic functions (like Common Lisp's (+ a) (+ a b) (+ a b c) (apply #'+ list) In a stack language, the number of inputs to One approach is to make a new word which takes an integer, and operates on that many items at the top of the stack together. Factor's "a" 1 narray "a" "b" 2 narray "a" "b" "c" 3 narray Another approach that is often used is to make a word which takes a sequence of values. If all the values are literal: { 5 } sum { 5 6 } sum { 5 6 7 } sum or if not: 2 3 + 6 7 3array sum This revision created on Sun, 9 Aug 2009 17:27:14 by mncharity (expanded "takes a sequence" example to clarify { } only works with literals) |
|
|
All content is © 2008-2010 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license. |
|