我一直在阅读 Peter Seibel 的书Practical Common Lisp,按照书中出现的顺序从网上提供的书中代码拼凑项目,到目前为止,我有一个文件可以依次编译和加载每一章的代码,并且这是我遇到问题的地方:到目前为止,当我为项目加载 FASL 时,我在 ID3v2 部分收到如下警告。
我不明白参数编号冲突出现在哪里。 UNSIGNED-INTEGER
似乎得到了它的两个关键字参数。此外,在我看来,DEFINE-BINARY-TYPE
宏将使用&rest
/接受任意数量的参数&body
。我想知道您是否有任何提示或建议。一些相关的输出和代码如下。任何和所有的帮助表示赞赏。
提前致谢,
; file: .../cl-playlist/id3v2.lisp
; in: DEFINE-BINARY-TYPE U1
; (BINARY-DATA:DEFINE-BINARY-TYPE ID3V2::U1
; NIL
; (ID3V2::UNSIGNED-INTEGER :BYTES 1 :BITS-PER-BYTE 8))
; ...
; ==>
; (BINARY-DATA:READ-VALUE 'ID3V2::UNSIGNED-INTEGER #:STREAM :BYTES 1
; :BITS-PER-BYTE 8)
;
; caught STYLE-WARNING:
; The function was called with six arguments, but wants exactly two.
“id3v2.lisp”中的违规函数如下所示,
(define-binary-type u1 () (unsigned-integer :bytes 1 :bits-per-byte 8))
使用
(define-binary-type unsigned-integer (bytes bits-per-byte)
(:reader (in)
(loop with value = 0
for low-bit
downfrom (* bits-per-byte (1- bytes)) to 0 by bits-per-byte do
(setf (ldb (byte bits-per-byte low-bit) value) (read-byte in))
finally (return value)))
(:writer (out value)
(loop for low-bit
downfrom (* bits-per-byte (1- bytes)) to 0 by bits-per-byte
do (write-byte (ldb (byte bits-per-byte low-bit) value) out))))
来自“binary-data.lisp”中的以下内容
(defmacro define-binary-type (name (&rest args) &body spec)
; (defmacro define-binary-type (name &rest args &body spec)
(with-gensyms (type stream value)
`(progn
(defmethod read-value ((,type (eql ',name)) ,stream &key ,@args)
(declare (ignorable ,@args))
,(type-reader-body spec stream))
(defmethod write-value ((,type (eql ',name)) ,stream ,value &key ,@args)
(declare (ignorable ,@args))
,(type-writer-body spec stream value)))))