Variadic function: Difference between revisions

Forth
m (Moved to Basic learning cat)
(Forth)
Line 64:
println(y)
}
 
=={{header|Forth}}==
Words taking variable numbers of arguments may be written by specifying the number of parameters to operate upon as the top parameter. There are two standard words which operate this way: PICK and ROLL.
 
: sum ( x_1 ... x_n n -- sum ) 1 ?do + loop ;
4 3 2 1 4 sum . \ 10
 
Alternatively, you can operate upon the entire parameter stack for debugging by using the word DEPTH, which returns the number of items currently on the stack.
 
: .stack ( -- ) depth 0 ?do i pick . loop ;
 
=={{header|Io}}==
Anonymous user