3 ms·
Why would you do that in a doc-string? If you just `declare` the types with `declare` instead of putting them in the docstring, the compiler can also take advan
by emidln 11y ago
Why would you do that in a doc-string? If you just `declare` the types with `declare` instead of putting them in the docstring, the compiler can also take advantage of them. Then the system can automatically tell you that information back. It will also infer the return type for you automatically.
A trivial example (your editor can do this for you):
(defun add-string (a b)
(declare (number a) (string b))
"Parses b and adds to a"
(+ a (parse-integer b)))
CL-USER> (describe #'add-string)
#<FUNCTION ADD-STRING>
[compiled function]
Lambda-list: (A B)
Derived type: (FUNCTION (NUMBER STRING) (VALUES NUMBER &OPTIONAL))
Documentation:
Parses b and adds to a
Source file: /home/bja/foo.lisp
- mcculley 11y agoAh. That's nice. Thanks for pointing that out. That's something I've not seen in any introductions to Common Lisp. Are all of the standard functions documented this way?
- gkya 11y agoWhy not check your favourite implementation's source?
- mcculley 11y agoI have perused the source for Steel Bank Common Lisp, but it's far from clear if everything in the standard is documented this way or if one must keep a tab open to the Common Lisp specification for such references.
- emidln 11y agoI think so (at least on sbcl). I don't use common lisp all that much, I mostly knew about describe due to the which-key menus in the emacs SLIME environment.
- wes-exp 11y agoThere is also ftype: (declaim (ftype (function (number string) number) add-string)) (defun add-string (a b) ...)