I’m looking for something similar to Javascript’s arguments array:
function parent(){
child.apply(this.arguments);
}
I’m aware of the dot notation for variable argument lengths and also scheme’s apply function.
This doesn’t seem to work as the dot is taken to be the first argument:
(define (parent .)
(list .))
(parent 1 3 4 6 7)
Error: bad argument count - received 5 but expected 1: #<procedure (array arg-list)>
This works but isn’t ideal. I’d like to call the function without the extra syntax to define the args list:
(define (parent args-list)
(apply list args-list))
(parent 1 3 4 6 7)
Error: bad argument count - received 5 but expected 1: #<procedure (array args-list)>
(parent `(1 3 4 6 7))
(1 3 4 6 7)
The correct syntax is:
Use it like this:
Inside the procedure, all the arguments will be bound to a list named
args-list. In the above snippet,args-listwill have'(1 2 3 4 5)as its value. This is an example of how variadic functions work in Scheme.For the sake of completeness, the same mechanism can be used for anonymous functions, too (notice that
args-listis not surrounded by parenthesis):