How one can write in Scheme function Fix-first-parameter and Fix-second-parameter that for given function F of n arguments (parameters) and given number A, will return a new function (lets donote if by G) of (n-1) arguments (parameters), such that:

Very important is fact, that arguments x_1, ..., x_n-1 are given not as a list by directly. I don't know how to extract (currying?) them and write a function that will work properly on the examples given above. I hope that some of you will help me.

blooper wrote:Very important is fact, that arguments x_1, ..., x_n-1 are given not as a list by directly. I don't know how to extract (currying?) them and write a function that will work properly on the examples given above. I hope that some of you will help me.

To create a function that receives an arbitrary number of arguments, you need to use the directive &rest in the argument list of the function, like this:

Inside this function, except for the first and second arguments, all the others are rolled in a list. The variable other-args is that list. For instance, calling the function above with args 1, 2, 3, 4, 5 and 6, you will have first-arg = 1, second-arg = 2 and other-args = (3 4 5 6).

You can also do the opposite (unroll a list into the arguments of a function) using the function apply. For instance, this function will sum all its arguments.

Are you sure that &rest directive is acceptable in Scheme or is it just available in CL? I've tried to used it DrScheme with R5RS language turned on, but it doesn't work as it should have - it is trying to take &rest as if it was one of the arguments...

blooper wrote:Are you sure that &rest directive is acceptable in Scheme or is it just available in CL? I've tried to used it DrScheme with R5RS language turned on, but it doesn't work as it should have - it is trying to take &rest as if it was one of the arguments...

Hum, sorry, my mistake. I was sure I had tested this here with tinyscheme, but I was wrong. Well, there is an analogous way, though: