If statement 不是程序,真的吗?

If statement 不是程序,真的吗?,if-statement,scheme,If Statement,Scheme,我已经想了两个小时了!请考虑以下代码: (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

我已经想了两个小时了!请考虑以下代码:

(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)))))
火箭方案编译器给我错误信息: 应用:不是一个程序; 应为可应用于参数的过程 给定:(##) 论据。。。: #

它指向(缺点)部分

下面的代码使用相同的if结构,可以工作:

(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))))))
编辑:PowListF被赋予函数列表作为参数,返回相同的列表s.t每个函数由自身组成(其索引+1)次

用法: (列表编号:PowListF(列表编号:lambda(x)x)(lambda(x)(expt x 2)))1)2) 值应为2^2^2=2^4=16

编辑2:

这就是解决方案:

(define (FuncPow f n) 
  (if (= 0 n)
      f
      (lambda (x) (f ((FuncPow f (- n 1)) x)))))

问题在于:
(FuncPow(f(-n1))x)

调用
f
的结果必须是procedure(我假设您返回一个procedure)


然后您进一步将
f
赋值为:
(list ref list n)

它确实返回过程,不是吗?我的假设是,list是过程列表,所以(list ref list n)是索引n处的过程……那么我猜这是调用
(f(-n 1))的结果
没有返回一个。我编辑了o.q来解释我需要做什么,也许你可以帮我让它工作。你能添加一个示例用法吗?