【发布时间】:2016-07-16 12:21:01
【问题描述】:
我最近发现可以为结构添加类型限制,但是无论出于何种原因,它都不允许 0.0 作为短浮点数的合法默认值,但它确实允许 100.0。
当我尝试在 CLisp 中运行 make-ship 以创建 ship 结构的实例时出现以下错误:
[4]> (make-ship)
*** - THE: #:ENERGY evaluated to the values (0.0), not of type SHORT-FLOAT
The following restarts are available:
ABORT :R1 Abort main loop
谁能解释到底发生了什么,为什么我不允许使用 0.0?
这是行为不端的代码:
(defstruct ship
location ;; fields like these have an undecided type at the moment
(energy 0.0 :type short-float)
cargo
crew
shields
(hull-integrity 100.0 :type short-float))
【问题讨论】:
-
不是完整的解释,但是你尝试过各种后缀,例如
0.0d等吗? -
@JoshuaTaylor 我什至不知道后缀是什么...
-
见lispworks.com/documentation/HyperSpec/Body/02_cbb.htm。我认为 s 应该可以工作。
标签: types common-lisp record