我最近问了一个question关于 sbcl,其响应提到了两个我不知道的函数:#'sb-ext:string-to-octets
和 #'sb-ext:octets-to-string
。除了回答我的问题之外,这还教会了我应该浏览包 sb-ext 的外部符号,看看还有什么可能有用。
我的问题(与 sbcl 相关)是这样的:除了浏览包 sb-ext 的外部符号外,是否还有一些其他手册描述包 sb-ext 和其他添加内容(我试图避免使用这个词“扩展”,因为它是 sbcl 的特定技术术语?例如,#'sb-ext:string-to-octets
和 #'sb-ext:octets-to-string
没有在 sbcl manual 中讨论。 .
最佳答案
正如@svante 在另一个问题的一个答案中指出的那样,对于类似的事情,我更喜欢使用另一个库来实现 postabiliyt,并且通常有很好的记录,如 babel .
如果符号在 ansi common lisp 中,通常用于检查 common lisp 中的 doc,您应该检查 teh clhs sly和 slime有一个很好的设施。
通常我会按照以下步骤进行:
CL-USER> (documentation 'sb-ext:octets-to-string 'function)
NIL
CL-USER> (describe 'sb-ext:octets-to-string)
SB-EXT:OCTETS-TO-STRING
[symbol]
OCTETS-TO-STRING names a compiled function:
Lambda-list: (VECTOR &KEY (EXTERNAL-FORMAT DEFAULT) (START 0) END)
Derived type: (FUNCTION
((VECTOR (UNSIGNED-BYTE 8)) &KEY (:EXTERNAL-FORMAT T)
(:START T) (:END T))
*)
Source file: SYS:SRC;CODE;OCTETS.LISP
; No values
describe 函数总能为您提供符号的相关信息,然后您可以使用 sly 或 slime 使用 M- 访问源代码。
(defun octets-to-string (vector &key (external-format :default) (start 0) end)
(declare (type (vector (unsigned-byte 8)) vector))
(with-array-data ((vector vector)
(start start)
(end end)
:check-fill-pointer t)
(declare (type (simple-array (unsigned-byte 8) (*)) vector))
(let ((ef (maybe-defaulted-external-format external-format)))
(funcall (ef-octets-to-string-fun ef) vector start end))))
最后你可以去 teh 存储库阅读测试,在这种情况下去 github SBCL 存储库并寻找这个功能提供源代码测试,你可以阅读这些测试以轻松使用该功能:
https://github.com/sbcl/sbcl/search?utf8=%E2%9C%93&q=string-to-octets&type=
像这样:
https://github.com/sbcl/sbcl/blob/622c9daf9bb41ef9ad4b8a063c62c4baf59a1c1a/tests/octets.pure.lisp
关于documentation - sbcl:(例如)#'sb-ext:string-to-octets 的附加文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46262961/