EVAL:未定义的函数.在Common LISP中用作参数



开始学习LISP并编写了两个简单的程序,使用函数作为参数。

第一:

;gnu clisp  2.49.60
(defun pf (x f123) (cond ((null x) nil)
(T (cons ( f123 (car x) ) (pf (cdr x) f123)))))
(defun f2 (x) (* x x)) 
(print (pf '(1 2 3 4) 'f2 ) )

第二:

(defun some1(P1 P2 x)
(if (not( = (length x) 0))
(cond 
(
(or ( P1 (car x) ) ( P2 (car x)) )
(cons (car x) (some1 P1 P2 (cdr x) ))
)
(t (some1 P1 P2 (cdr x) ))
)
)
)
(print (some1 'atom 'null '( 5 1 0 (1 2) 10 a b c) )     )

这两个程序都不起作用。我不知道如何修复它:(

(函数f123 x y z(是有效的,因此结果:

;gnu clisp  2.49.60
(defun pf (x f123)
(cond ((null x) nil)
(T (cons (funcall f123 (car x))
(pf (cdr x) f123)))))
(defun f2 (x) (* x x)) 
(print (pf '(1 2 3 4) 'f2))

;gnu clisp  2.49.60
(defun eq0(x)
(if (= x 0)
t
nil))
(defun bg10(x)
(if (> x 10)
t
nil))
(defun some1 (P1 P2 x)
(if (not (= (length x) 0))
(cond 
((or (funcall P1 (car x)) (funcall P2 (car x)))
(cons (car x) (some1 P1 P2 (cdr x))))
(t (some1 P1 P2 (cdr x))))))
(print (some1 'eq0 'bg10 '(5 0 0 11)))

也许它对某人有用:(

最新更新