I have the following variadic function (define doSomething (lambda (x . rest) .... The function is called by using numbers, for example: (doSomething 1 2 3 4 5) (so with that call x would be 1 and rest would be (2 3 4 5)).
When I try to recursively call the function and put the second number (2) as x and rest as (3 4 5) I somehow receive the rest parameter as a list of list: ((3 4 5)).
This is how I currently try to call the function again:
(+ x (doSomething (car rest) (cdr rest)))
It is worth mentioning that I’m using Pretty Big. Please advise, thanks.
So you’re mix and matching what rest is, in your first call
In your subsequent calls you’ll end up with
because
restis a variadic argument, so it takes everything after the first argument and makes it a list calledrestfor you, hence the double-listing. You’ll probably want to be usingapplyor something, ie something like: