作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SBCL 64位,1.1.7
如果我想创建一个包并使用package:CL中的一些符号,我将创建一个像这样的包:
(defpackage :foo
(:import-from :cl
:defun :defmacro :in-package
:null :car :cdr :cons :if
:eq))
(defun test (&optional a))
(test)
invalid number of arguments: 0
[Condition of type SB-INT:SIMPLE-PROGRAM-ERROR]
Restarts:
0: [RETRY] Retry SLIME interactive evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [REMOVE-FD-HANDLER] Remove #<SB-IMPL::HANDLER INPUT on descriptor 10: #<CLOSURE (COMMON-LISP:LABELS SWANK-BACKEND::RUN :IN SWANK-BACKEND:ADD-FD-HANDLER) {100490B95B}>>
3: [ABORT] Exit debugger, returning to top level.
(defmacro test (&rest body))
(test)
error while parsing arguments to DEFMACRO TEST:
invalid number of elements in
()
to satisfy lambda list
(&REST BODY):
exactly 2 expected, but 0 found
[Condition of type SB-KERNEL::ARG-COUNT-ERROR]
最佳答案
我相信这将为这个问题提供一些启发;)
CL-USER> (defpackage :foo
(:import-from :cl
:defun :defmacro :in-package
:null :car :cdr :cons :if
:eq))
#<PACKAGE "FOO">
CL-USER> (in-package :foo)
#<COMMON-LISP:PACKAGE "FOO">
FOO> (defun bar (&optional baz))
; in: DEFUN BAR
; (SB-INT:NAMED-LAMBDA FOO::BAR
; (FOO::&OPTIONAL FOO::BAZ)
; (BLOCK FOO::BAR))
;
; caught COMMON-LISP:STYLE-WARNING:
; suspicious variable in lambda list: &OPTIONAL.
;
; caught COMMON-LISP:STYLE-WARNING:
; suspicious variable in lambda list: &OPTIONAL.
;
; caught COMMON-LISP:STYLE-WARNING:
; The variable &OPTIONAL is defined but never used.
;
; caught COMMON-LISP:STYLE-WARNING:
; The variable BAZ is defined but never used.
;
; compilation unit finished
; caught 4 STYLE-WARNING conditions
BAR
FOO> (in-package :cl)
#<PACKAGE "COMMON-LISP">
CL> (defpackage :foo
(:import-from :cl
:defun :defmacro :in-package :&optional
:null :car :cdr :cons :if
:eq))
Select a symbol to be made accessible in package FOO:
1. COMMON-LISP:&OPTIONAL
2. FOO::&OPTIONAL
Enter an integer (between 1 and 2): 1
#<PACKAGE "FOO">
CL> (in-package :foo)
#<COMMON-LISP:PACKAGE "FOO">
FOO> (defun bar (&optional baz))
; in: DEFUN BAR
; (SB-INT:NAMED-LAMBDA FOO::BAR
; (&OPTIONAL FOO::BAZ)
; (BLOCK FOO::BAR))
;
; caught COMMON-LISP:STYLE-WARNING:
; The variable BAZ is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
COMMON-LISP:STYLE-WARNING: redefining FOO::BAR in DEFUN
BAR
FOO>
&optional
,
&rest
等只是与其他符号一样的符号,您也需要导入这些符号。但是,也许这不是从
cl
包中导入的最佳方法……除非您确定那是您所需要的。以防万一:您可以用
:use
整个软件包,而不是逐个符号
:import-from
。
关于common-lisp - common-lisp中有关可选参数的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16837360/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!