Here is some function documentation sugar functions assuming the
document function that might show up in later code here is
the code from Marks post.
(transparent SETF)
(define document
F String -> (let Type (qi::pretty-type (typecheck [] F A))
DocString (FORMAT NIL "~A~%The type is ~A" String Type)
Attach (SETF (DOCUMENTATION F FUNCTION)) DocString)
documented)
(define documentation
F -> (DOCUMENTATION F FUNCTION))
(declare document [[A --> B] --> string --> symbol])
(declare documentation [[A --> B] --> string])
1. doc-define0 to get lispy documentation strings inside functions
(define doc-define0
[doc-define Name Str | L] -> [do [define Name | L]
[document Name Str]]
X -> X)
and sugaring it by
(sugar in doc-define0 1)
Now this will be used as
(doc-define id
"The identity-map" {A --> A}
X -> X)
Now we can see the documentation for id
(21-) (documentation id)
"identity function
The type is [A --> A]" : string
Another sugar macro can be used to get java style documentation strings by combining
the definition of several functions.
Here is the sugar fuinction
(define doc-defines0
[doc-defines Str Def |L] -> (let Name (CADR Def)
[do Def
[document Name Str]
(doc-defines0 [doc-defines|L])])
[doc-defines] -> finished-defines
X -> X)
And here is how it works
(doc-defines
"The identity map"
(define id {A --> A} X -> X)
"verbose addition"
(define addition
{number --> number --> number}
X Y -> (+ X Y)))
And looking at the docstrings you get
(61+) (documentation id)
"The identity map
The type is [A --> A]" : string
(62+) (documentation addition)
"verbose addition
The type is [number --> [number --> number]]" : string