lisp - lisp 将值传递给函数?
问题描述
我是 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
推荐阅读
- css - @keyframes 无限循环
- python - 使用 GraphAPI 的 Facebook Messenger 对话的日期过滤器
- discord - 被 Discord 阻止的 Repli Discord 机器人
- postgresql - 如何从 postgres 的表中删除超过 90 天的记录
- php - 如何在php中从复活节日期减去1周
- amazon-web-services - API 网关 SQS 与 SendMessageBatch 的集成
- colors - 有没有办法以严格的 RGB 格式表示 Alpha 通道值?
- python - 在 tkinter 赋值之前引用的局部变量
- powershell - PowerShell DbaTools 将 Hashtable 传递给 Invoke-DbaQuery
- stackblitz - 无法在 StackBlitz 上登录 Firebase