Suppose there are two functions, f and v. Assume further that v returns a list of length n and f expects exactly n arguments. I am looking for the correct syntax in Scheme for applying f to the list returned by v.
If I use the syntax (f (v v-arguments))
then I get an error about f expectsing n arguments but receiving only one argument (which is the list returned by v).
If I use the syntax (f . (v v-arguments))
, then the problem is too many arguments passed to f.
The best I could do (for the case when f expects two arguments) is this:
(let ((output-of-v (v v-arguments)))
(f (car output-of-v) (cadr output-of-v)))
I am sure there must be a better way and I would be grateful for any advice!
It seems you're looking for apply:
(apply f (v v-arguments))
As explained here, the apply
function applies a function to a list of arguments, effectively passing them as positional arguments to that function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With