Elisp定义阿克曼函数

问题描述 投票:0回答:1

我正在阅读SICP,并参考其Exercise 1.10. The following procedure computes a mathematical function called Ackermann's function.

(define (A x y)
  (cond ((= y 0) 0)
        ((= x 0) (* 2 y))
        ((= y 1) 2)
        (else (A (- x 1)
                 (A x (- y 1))))))

用elisp重写

(defun A (x y)
  (cond ((= y 0) 0)
        ((= x 0) (* 2 y))
        ((= y 1) 2)
        (else (A (- x 1)
                 (A x (- y 1))))))

(A 1 10)

报告错误:A: Symbol’s value as variable is void: else

因此请参阅elisp的控制结构,在各种替代方法中都将丢失。

您能否提供提示以condelse定义该功能>

我正在阅读SICP并参考其练习1.10。以下过程将计算一个称为Ackermann函数的数学函数。 (定义(A x y)(cond((= y 0)0)((= x 0)(* 2 y))...

elisp
1个回答
1
投票

在Emacs Lisp中,您使用t而不是else。在这种情况下,Language Reference

© www.soinside.com 2019 - 2024. All rights reserved.