For example ((fn-stringappend string-append) "a" "b" "c")
I know how to handle this (f x y z)
. But what if there's an unknown number of parameters? Is there any way to handle this kind of problem?
相关问题
- Generating powerset in one function, no explicit r
- What is fixed point?
- unfold function in scheme
- C++ variadic template arguments method to pass to
- returns the first n of list
相关文章
- Does learning one Lisp help in learning the other?
- What is the definition of “natural recursion”?
- How to pass vararg as array to function in Kotlin?
- Scala variadic functions and Seq
- Necessity of forward-declaring template functions
- How to expose a c++ function taking variable argum
- How do I define a sub environment in scheme?
- Why is it legal in a function definition to make s
In addition to Óscar López's answer, you can also make an anonymous function of variable arguments like so:
Where again, inside the
lambda
,args
is a list of the arguments passed.In Scheme you can use the dot notation for declaring a procedure that receives a variable number of arguments (also known as varargs or variadic function):
Inside
procedure
,args
will be a list with the zero or more arguments passed; call it like this:As pointed out by @Arafinwe, here's the equivalent notation for an anonymous procedure:
Call it like this:
Remember that if you need to pass the parameters in a list of unknown size to a variadic function you can write it like this:
UPDATE:
Regarding the code in the comments, this won't work as you intend:
I believe you meant this:
With a bit of syntactic sugar the above procedure can be further simplified to this:
But that's just a long way for simply writing:
Is this what you need?
Because anyway that's equivalent to the following:
string-append
already receives zero or more arguments (at least, that's the case in Racket)