I need to understand how can I access to an input of a function which is given to another function as an input.
For example; I have a function called f which simply does (define f (lambda (x) (if (null? x) #t (car x)))) this. I need to write a function which takes this f as an input and returns another function such that,
-Define a function (twoback f) which takes a function f as its input.
-As its output, it should return a new function g which has the following behaviour:
g(x) = #t if x is the empty list or a list of length 1.
= f(y) where y=(cdr x) otherwise.
And the function will called like this : ((twoback f3) (list #t #f #t #f))
So actually my question is : How can I access the list given with the function call in the function that I’m going to write(the twoback function) ? Because i need to check whether it is empty or not.
Short answer, by currying the
xparameter. Something like this:The above will define a procedure called
twobackwhich receivesfas parameter, and in turn it will return a new procedure which receivesxas parameter. This second procedure being returned is the one calledgin the question, from it you can access bothfandxas you would normally do.Now just complete the
...part with the expected output.