从未调用过 Lisp 函数


(defun func (in s f l)
(cond 
((null in) (append l (list (list 'end (+ 1 f)))))
((eq (car in) 'foo) (foo-asd (cdr in) s f l)) 
((atom (car in))(atom-asd in (+ 1 s) (+ 1 f) l))
))

.

(defun atom-asd (in s f l)
(cond ((eql in nil) ())
(append l (list (list 'frob s (car in) (+ 1 f))))))

.

(defun foo-asd (in s f l)
(cond 
((eql in nil) (append l (list (list 'frob s 'myst f))))
((func in s f (append l (list (list 'frob s 'myst (+ 1 f))))))
((foo-asd (cdr in) s f l))
))

. 关于这段代码,如果调用(func '(foo x y) 0 0 ())函数foo-asd将被调用,那么再次调用func,它将进入函数atom-asd,当atom-asd结束时执行,所有程序结束,而不调用递归调用foo-asd。我需要foo-asd才能被召唤,但我不明白为什么在atom-asd结束后不召唤它。

[4]> (trace func)
;; Tracing function func.
(func)
[5]> (trace atom-asd)
;; Tracing function atom-asd.
(atom-asd)
[6]> (trace foo-asd)
;; Tracing function foo-asd.
(foo-asd)
[7]> (func '(foo x y) 0 0 ())
1. Trace: (func '(foo x y) '0 '0 'nil)
2. Trace: (foo-asd '(x y) '0 '0 'nil)
3. Trace: (func '(x y) '0 '0 '((frob 0 myst 1)))
4. Trace: (atom-asd '(x y) '1 '1 '((frob 0 myst 1)))
*** - cond: variable append has no value
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead of append.
STORE-VALUE    :R2      Input a new value for append.
ABORT          :R3      Abort main loop
Break 1 [8]>

所以在atom-asd

(defun atom-asd (in s f l)
(cond
((eql in nil)
())
(append
l (list (list 'frob s (car in) (+ 1 f))))))

你有两个谓词。 一个测试(eql in nil)显然是nil的,然后它检查变量append是否具有非nil值。问题是append不是绑定变量。它是函数命名空间中的一个绑定,但在这里每个术语都包含在一组括号中append因此它本身就是被测试的表达式。你可能的意思是,当第一个学期没有开始时,它应该(append ...),你应该这样写:

(defun atom-asd (in s f l)
(cond
((eql in nil)
())
(t
(append l (list (list 'frob s (car in) (+ 1 f)))))))

使用此版本,我们得到一个结果:

[8]> (func '(foo x y) 0 0 ())
5. Trace: (func '(foo x y) '0 '0 'nil)
6. Trace: (foo-asd '(x y) '0 '0 'nil)
7. Trace: (func '(x y) '0 '0 '((frob 0 myst 1)))
8. Trace: (atom-asd '(x y) '1 '1 '((frob 0 myst 1)))
8. Trace: atom-asd ==> ((frob 0 myst 1) (frob 1 x 2))
7. Trace: func ==> ((frob 0 myst 1) (frob 1 x 2))
6. Trace: foo-asd ==> ((frob 0 myst 1) (frob 1 x 2))
5. Trace: func ==> ((frob 0 myst 1) (frob 1 x 2))
((frob 0 myst 1) (frob 1 x 2))

最新更新