Function with fixed parameter
Posted: Wed May 20, 2009 7:07 am
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:
G(x_1, x_2, x_3, ..., x_n-1) = F(a, x_1, x_2, x_3, ..., x_n-1) (in case of Fix-first-parameter function),
G(x_1, x_2, x_3, ..., x_n-1) = F(x_1, a, x_2, x_3, ..., x_n-1) (in case of Fix-second-parameter function).
For example:
1.
should return:
2.
should return:
3.
should return:
---
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.
G(x_1, x_2, x_3, ..., x_n-1) = F(a, x_1, x_2, x_3, ..., x_n-1) (in case of Fix-first-parameter function),
G(x_1, x_2, x_3, ..., x_n-1) = F(x_1, a, x_2, x_3, ..., x_n-1) (in case of Fix-second-parameter function).
For example:
1.
Code: Select all
(define function1 (lambda (x y z) (+ x (* 2 y) (* 3 z))))
(display ((Fix-first-parameter function1 1) 2 3))
Code: Select all
14
Code: Select all
(define function1 (lambda (x y z) (+ x (* 2 y) (* 3 z))))
(display ((Fix-second-parameter function1 1) 2 3 ))
Code: Select all
13
Code: Select all
(define function2 (lambda (x y z s) (cons (+ x (* 2 y)) (+ z (* 4 s)))))
(display ((Fix-second-parameter function2 2) 1 3 2))
Code: Select all
(5 . 11)
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.