I been trying to figure this out for like 2 hours now! please Consider the following code:
(define (PowListF list)
(PowListFHelp list (- (length list) 1)))
(define (FuncPow f n)
(if (= 0 n)
f
(lambda (x)
(FuncPow (f (- n 1)) x))))
(define (PowListFHelp list n)
(if (= n 0)
(list (list-ref list 0))
(cons (FuncPow (list-ref list n) n)
(PowListFHelp list (- n 1)))))
The rocket Scheme compilers give me error:
application: not a procedure;
expected a procedure that can be applied to arguments
given: (# #)
arguments…:
#
and it points to the (cons part…
and The following code, that uses the same if structure, does work:
(define (polyCheb n)
(reverse (polyChebHelp n)))
(define (polyChebHelp n)
(if (= n 0)
(list (polyChebFunc n))
(cons (polyChebFunc n)
(polyChebHelp (- n 1)))))
(define (polyChebFunc n)
(if (= n 0)
(lambda (x) 1)
(if (= n 1)
(lambda (x) x)
(lambda (x)
(- (* (* 2 x)
((polyChebFunc(- n 1)) x))
((polyChebFunc(- n 2)) x))))))
EDIT: PowListF is being given list of functions as parameter, returns the same list s.t every function is composed with itself (its index + 1) times…
usage:
((list-ref (PowListF (list (lambda (x) x) (lambda (x) (expt x 2)))) 1) 2)
value should be 2^2^2=2^4=16
EDIT 2:
This was the solution :
(define (FuncPow f n)
(if (= 0 n)
f
(lambda (x) (f ((FuncPow f (- n 1)) x)))))
The problem lies with:
(FuncPow(f (- n 1)) x)The result of calling
fmust be procedure (I assume this as you return a procedure).You further then ‘assign’
fas:(list-ref list n).