小编Lex*_*Lex的帖子

删除Common Lisp中的类型

Common Lisp是否为使用deftype创建的未定义类型提供了便利 ?

我没有在Hyperspec中找到任何关于它的内容.

lisp common-lisp

5
推荐指数
1
解决办法
167
查看次数

类型的类型谓词

我正在寻求提高我收到的编译器警告的质量和数量 - 在Common Lisp中是否有一种方法可以在声明的类型和实例上包含类型谓词 - 特定于实现的答案很好,我很感兴趣看看它是如何完成的,如果有人这样做的话.

在CCL中编译以下内容:

(defun non-list (o)
  (not (listp o)))

(deftype non-list ()
  '(satisfies non-list))

(defun example (a)
  (list a))

(declaim (ftype (function (non-list) list) example))

(defun hmm ()
  (declare (optimize (debug 3) (safety 3)))
  (let ((a '(a b c))
    (b '(d e f)))
    (declare (type list a))
    (example '(g h i))
    (example a)
    (example b)))
Run Code Online (Sandbox Code Playgroud)

我会在第一次调用时收到编译器警告example- 提供可以检查的实例satisfies.这很好,使用调试设置我会得到一个好的运行时错误.我想知道的是,如果我能写出如下内容:

(defun non-list-typep (type)
  (not (subtypep type 'list)))
Run Code Online (Sandbox Code Playgroud)

并以某种方式集成它,以便至少第二次调用 - (example a)将在编译时警告,因为它的声明类型list …

common-lisp

3
推荐指数
1
解决办法
413
查看次数

标签 统计

common-lisp ×2

lisp ×1