lisp - sbcl:defmacro 中的马弗风格警告

标签 lisp common-lisp compiler-warnings sbcl

在 sbcl 中,我知道在 defun 中同时使用 &Optional 和 &key 时可以消除预期的消息,但这在 defmacro 中似乎不起作用。 (我知道,我应该重新设计/重写,但这是遗留代码。)

当我编译这个文件时...

(declaim (sb-ext:muffle-conditions style-warning))

(defun wilma (&optional wilma1 &key wilma2 wilma3)
  (declare (ignore wilma1 wilma2 wilma3)))

(defmacro betty (&optional betty1 &key betty2 betty3)
  (declare (ignore betty1 betty2 betty3)))

...发生这种情况:

home:~/sbcl/experiments/style-warning.d$ sbcl --noinform
* (compile-file "5.lisp")

; compiling file "/u/home/sbcl/experiments/style-warning.d/5.lisp" (written 09 OCT 2017 03:31:44 PM):
; compiling (DECLAIM (MUFFLE-CONDITIONS STYLE-WARNING))
; compiling (DEFUN WILMA ...)
; compiling (DEFMACRO BETTY ...)
; file: /u/home/sbcl/experiments/style-warning.d/5.lisp
; in: DEFMACRO BETTY
;     (DEFMACRO BETTY (&OPTIONAL BETTY1 &KEY BETTY2 BETTY3)
;       (DECLARE (IGNORE BETTY1 BETTY2 BETTY3)))
; 
; caught STYLE-WARNING:
;   &OPTIONAL and &KEY found in the same lambda list: (&OPTIONAL BETTY1 &KEY BETTY2
;                                                      BETTY3)
; 
; compilation unit finished
;   caught 1 STYLE-WARNING condition


; /u/home/sbcl/experiments/style-warning.d/5.fasl written
; compilation finished in 0:00:00.018
#P"/u/home/sbcl/experiments/style-warning.d/5.fasl"
T
NIL
* (exit)
home:~/sbcl/experiments/style-warning.d$ 

如何抑制这些诊断?

编辑1:

由于这是遗留代码,我只是为了 sbcl 准备而修改它,然后不管它,所以我没有理由不能在使用它的任何代码中执行类似的操作:

home:~/sbcl/experiments/style-warning.d$ sbcl --noinform
* (with-open-file (*error-output* "/dev/null" :direction :output :if-exists :append) 
(compile-file "5.lisp"))

; compiling file "/u/home/sbcl/experiments/style-warning.d/5.lisp" (written 09 OCT 2017 03:31:44 PM):
; compiling (DECLAIM (MUFFLE-CONDITIONS STYLE-WARNING))
; compiling (DEFUN WILMA ...)
; compiling (DEFMACRO BETTY ...)

; /u/home/sbcl/experiments/style-warning.d/5.fasl written
; compilation finished in 0:00:00.017
#P"/u/home/sbcl/experiments/style-warning.d/5.fasl"
T
NIL
* (exit)
home:~/sbcl/experiments/style-warning.d$ 

但是有什么东西可以抑制宏定义中的样式警告吗?

最佳答案

你需要运行

(declaim (sb-ext:muffle-conditions style-warning))

编译(defmacro betty ...)形式之前。

实现这一点的一种方法是

$ sbcl --non-interactive --eval '(declaim (sb-ext:muffle-conditions style-warning))' --eval '(compile-file "5")'
This is SBCL 1.4.0, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
; compiling file "/Users/sds/lisp/5.lisp" (written 09 OCT 2017 09:51:51 PM):
; compiling (DEFUN WILMA ...)
; compiling (DEFMACRO BETTY ...)

; /Users/sds/lisp/5.fasl written
; compilation finished in 0:00:00.010

其中文件5.lisp仅包含wilmabetty:

(defun wilma (&optional wilma1 &key wilma2 wilma3)
  (declare (ignore wilma1 wilma2 wilma3)))

(defmacro betty (&optional betty1 &key betty2 betty3)
  (declare (ignore betty1 betty2 betty3)))

关于lisp - sbcl:defmacro 中的马弗风格警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46656090/

相关文章:

list - 如何将列表转换为 LISP 中的集合?

Lisp函数调用错误

clojure - 惯用的方式使用 for,同时仍然保持高性能

loops - Lisp 帮助 |错误 : Duplicate binding in LOOP : (result)

postgresql - 在 CL 后现代什么 :col-type to use for Many to Many field?

java - TreeMap 通用参数警告

c - 使用 GCC 将 warn_unused_result 应用于所有函数

c++ - 窄转换编译警告。如何解决?

lisp - 搜索包含 lists 或 conses 的列表

object - Lisp:基本的面向对象计数器