element-of-set-p:Symbol 的变量值是 void:false
element-of-set-p: Symbol’s value as variable is void: false
我从 sicp
中 minic 一个 intersction-set
操作
#+name: case-2.3.3-element-of-set-p
#+BEGIN_SRC elisp :session sicp :results value
(defun element-of-set-p(x set)
(cond ((null set) false)
((equal x (car set)) t)
(t (element-of-setp x (cdr set)))))
(element-of-set-p 1 (list 1 2 3))
#+END_SRC
#+RESULTS: case-2.3.3-element-of-set-p
: t
和交集
#+BEGIN_SRC elisp :session sicp :results value
(defun intersection-set (set1 set2)
(cond ((or (null set1) (null set2))
'())
((element-of-set-p (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1)
set2)))
(t (intresection-set (cdr set1)
set2))))
(trace-function #'intersection-set)
(intersection-set (list 1 2) (list 2 3 4))
#+END_SRC
报错:
element-of-set-p: Symbol’s value as variable is void: false
有什么问题吗?
您的代码中有几个拼写错误:
- 不是
element-of-setp
,是element-of-set-p
- 不是
intresection-set
,是intersection-set
- 不是
false
,是nil
这应该有效:
(defun element-of-set-p (x set)
(cond ((null set) nil)
((equal x (car set)) t)
(t (element-of-set-p x (cdr set)))))
(defun intersection-set (set1 set2)
(cond ((or (null set1) (null set2))
'())
((element-of-set-p (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1) set2)))
(t (intersection-set (cdr set1) set2))))
我从 sicp
中 minic 一个intersction-set
操作
#+name: case-2.3.3-element-of-set-p
#+BEGIN_SRC elisp :session sicp :results value
(defun element-of-set-p(x set)
(cond ((null set) false)
((equal x (car set)) t)
(t (element-of-setp x (cdr set)))))
(element-of-set-p 1 (list 1 2 3))
#+END_SRC
#+RESULTS: case-2.3.3-element-of-set-p
: t
和交集
#+BEGIN_SRC elisp :session sicp :results value
(defun intersection-set (set1 set2)
(cond ((or (null set1) (null set2))
'())
((element-of-set-p (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1)
set2)))
(t (intresection-set (cdr set1)
set2))))
(trace-function #'intersection-set)
(intersection-set (list 1 2) (list 2 3 4))
#+END_SRC
报错:
element-of-set-p: Symbol’s value as variable is void: false
有什么问题吗?
您的代码中有几个拼写错误:
- 不是
element-of-setp
,是element-of-set-p
- 不是
intresection-set
,是intersection-set
- 不是
false
,是nil
这应该有效:
(defun element-of-set-p (x set)
(cond ((null set) nil)
((equal x (car set)) t)
(t (element-of-set-p x (cdr set)))))
(defun intersection-set (set1 set2)
(cond ((or (null set1) (null set2))
'())
((element-of-set-p (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1) set2)))
(t (intersection-set (cdr set1) set2))))