lisp 将值传递给函数?
lisp passing value to function?
我是 lisp 的新手,在我的代码中,我想将 3 个第一位转换为整数,并检查下一位中的个数是否等于那个,这是我的代码:
(defun new (vi n res)
(cond ((= vi nil) (cond ((= 0 res) t) ))
((= 2 n) (new (cdr vi) 1 (* (car vi) 4)))
((= 1 n) (new (cdr vi) 0 (+ (res) (* (car vi) 2))))
((= 0 n) (new (cdr vi) -1 (+ (res) (car vi ))))
((= vi nil) (nil))
((= -1 n) (new (cdr vi) -1 (- res (car vi))))))
我想测试一下但是当我写的时候:
(new ( 0 1 0 0 0 0 1 0 0 1 0) 2 0 )
错误 0 不是一个函数
我试过这个:
(new (list `0 `1 `0 `0 `0 `0 `1 `0 `0 `1 `0) 2 0 )
但它出错了
- =: (0 1 0 0 0 0 1 0 0 1 0) 不是数字
SBCL 在编译您的函数时显示这些警告:
; in: DEFUN NEW
; (= VI NIL)
;
; caught WARNING:
; Constant NIL conflicts with its asserted type NUMBER.
; See also:
; The SBCL Manual, Node "Handling of Types"
; in: DEFUN NEW
; (NIL)
;
; caught WARNING:
; The function NIL is undefined, and its name is reserved by ANSI CL so that even
; if it were defined later, the code doing so would not be portable.
; (RES)
;
; caught STYLE-WARNING:
; undefined function: COMMON-LISP-USER::RES
;
; compilation unit finished
; Undefined functions:
; NIL RES
; caught 2 WARNING conditions
; caught 1 STYLE-WARNING condition
我是 lisp 的新手,在我的代码中,我想将 3 个第一位转换为整数,并检查下一位中的个数是否等于那个,这是我的代码:
(defun new (vi n res)
(cond ((= vi nil) (cond ((= 0 res) t) ))
((= 2 n) (new (cdr vi) 1 (* (car vi) 4)))
((= 1 n) (new (cdr vi) 0 (+ (res) (* (car vi) 2))))
((= 0 n) (new (cdr vi) -1 (+ (res) (car vi ))))
((= vi nil) (nil))
((= -1 n) (new (cdr vi) -1 (- res (car vi))))))
我想测试一下但是当我写的时候:
(new ( 0 1 0 0 0 0 1 0 0 1 0) 2 0 )
错误 0 不是一个函数 我试过这个:
(new (list `0 `1 `0 `0 `0 `0 `1 `0 `0 `1 `0) 2 0 )
但它出错了
- =: (0 1 0 0 0 0 1 0 0 1 0) 不是数字
SBCL 在编译您的函数时显示这些警告:
; in: DEFUN NEW
; (= VI NIL)
;
; caught WARNING:
; Constant NIL conflicts with its asserted type NUMBER.
; See also:
; The SBCL Manual, Node "Handling of Types"
; in: DEFUN NEW
; (NIL)
;
; caught WARNING:
; The function NIL is undefined, and its name is reserved by ANSI CL so that even
; if it were defined later, the code doing so would not be portable.
; (RES)
;
; caught STYLE-WARNING:
; undefined function: COMMON-LISP-USER::RES
;
; compilation unit finished
; Undefined functions:
; NIL RES
; caught 2 WARNING conditions
; caught 1 STYLE-WARNING condition