Search code examples
documentationlispcommon-lispsbcl

sbcl: additional documentation for (for example) #'sb-ext:string-to-octets


I recently asked a question about sbcl for which a response mentioned two functions of which I wasn't aware: #'sb-ext:string-to-octets and #'sb-ext:octets-to-string. In addition to answering my question, this also taught me that I should browse through the external symbols of package sb-ext to see what else might be of use.

My question (sbcl-related) is this: other than browsing through the external symbols of package sb-ext, is there some other manual which describes package sb-ext, and other additions (I'm trying to avoid the word "extension" because it's a specific technical term) to sbcl? #'sb-ext:string-to-octets and #'sb-ext:octets-to-string, for example, are not discussed in the sbcl manual.


Solution

  • As pointed in one answer in the other question by @svante, for things like that I prefer to use another libray for postabiliyt and usually well documented like babel.

    Normally for checking doc in common lisp if the symbol is in the ansi common lisp, you should check teh clhs sly and slime has an excelent facility for that.

    And normally I proceed as follow:

    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
    

    The describe function always get you relevant info about the symbol, then you can go to teh source using sly or slime is with 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))))
    

    and finally you can go to teh repository for reading tests in this case going to the github SBCL repo and looking for this fucntion gives source code tests that you can read for getting an easy usage of the function:

    https://github.com/sbcl/sbcl/search?utf8=%E2%9C%93&q=string-to-octets&type=

    like this:

    https://github.com/sbcl/sbcl/blob/622c9daf9bb41ef9ad4b8a063c62c4baf59a1c1a/tests/octets.pure.lisp