SBCL 注意:类型断言太复杂,无法检查

问题描述 投票:0回答:2

无法破译 SBCL 编译器消息:

; in: DEFUN PURIFY-FILE
;     (DEFUN DEPENDENCIES::PURIFY-FILE (DEPENDENCIES::FILE)
;       "Transforms problematic symbols to benign NIL in file, before reading.
;      Returns a string of altered file content."
;       (LET ((DEPENDENCIES::FILE-STRING
;              (ALEXANDRIA:READ-FILE-INTO-STRING DEPENDENCIES::FILE))
;             (DEPENDENCIES::MODIFIED-FILE-STRING ""))
;         (SETF DEPENDENCIES::MODIFIED-FILE-STRING
;                 (CL-PPCRE:REGEX-REPLACE-ALL "[ trn]'[A-Za-z0-9!@$%&*_+:=<.>/?-]+"
;                                             DEPENDENCIES::FILE-STRING " NIL"))
;         (CL-PPCRE:REGEX-REPLACE-ALL
;          "[(][qQ][uU][oO][tT][eE][ trn]+[A-Za-z0-9!@$%&*_+:=<.>/?-]+[)]"
;          DEPENDENCIES::MODIFIED-FILE-STRING "NIL")))
; --> PROGN SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA
; ==>
;   #'(SB-INT:NAMED-LAMBDA DEPENDENCIES::PURIFY-FILE
;         (DEPENDENCIES::FILE)
;       (DECLARE (SB-C::TOP-LEVEL-FORM))
;       "Transforms problematic symbols to benign NIL in file, before reading.
;    Returns a string of altered file content."
;       (BLOCK DEPENDENCIES::PURIFY-FILE
;         (LET ((DEPENDENCIES::FILE-STRING #)
;               (DEPENDENCIES::MODIFIED-FILE-STRING ""))
;           (SETF DEPENDENCIES::MODIFIED-FILE-STRING #)
;           (CL-PPCRE:REGEX-REPLACE-ALL
;            "[(][qQ][uU][oO][tT][eE][ trn]+[A-Za-z0-9!@$%&*_+:=<.>/?-]+[)]"
;            DEPENDENCIES::MODIFIED-FILE-STRING "NIL"))))
;
; note: type assertion too complex to check:
; (VALUES STRING &OPTIONAL BOOLEAN &REST T).

我对此功能的规范是

(declaim (ftype (function (pathname) (values string (member NIL T))) purify-file))

是否与

CL-PPCRE:REGEX-REPLACE-ALL
返回多个值有关?如果是这样,如何使用
ftype
来指定所有多个值的类型 - 在本例中为 string & NIL 或 T?谢谢。

types common-lisp sbcl
2个回答
0
投票

事实上,正如消息所示,类型规范

(values string (member NIL T))
对于 SBCL 来说太复杂了。将类型规范更改为
(values t t)
有效。


0
投票

示例:

* (declaim (ftype (function () (values string boolean)) f))
(F)
* (defun f () (values "a" t))
F
* (describe #'f)
#<FUNCTION F>
  [compiled function]

Lambda-list: ()
Declared type: (FUNCTION NIL (VALUES STRING &OPTIONAL BOOLEAN &REST T))
Derived type: (FUNCTION NIL
               (VALUES (SIMPLE-ARRAY CHARACTER (1)) (MEMBER T) &OPTIONAL))

如您所见,

(VALUES STRING BOOLEAN)
隐式扩展为
&REST T
。要删除隐式
&REST
,请将其替换为空
&OPTIONAL
,如所示的派生类型:
(VALUES STRING BOOLEAN &OPTIONAL)

© www.soinside.com 2019 - 2024. All rights reserved.