Docstrings in my Chicken?
Here's a little bit of amateur code to enable the use of docstrings in Chicken Scheme.
;;; Docstrings for Chicken!
;; The hash-table that will contain the procedures and their associated
;; documentation strings as well as their code for later use.
(define *documentation-hash-table* (make-hash-table))
;; Documented define er-macro
(define-syntax (define* form r c)
(let* ((args-form (second form)) ; (proc args)
(proc-name (first args-form)) ; proc
(doc (third form)) ; "The docstring"
(body (drop form 3))) ; (everything else)
(hash-table-set! *documentation-hash-table* proc-name (list doc body)) ; insert the doc and code body
`(,(r 'define) ,args-form ,@body))) ; Define the procedure as normal
;; Example of a documented procedure, will print a nice-ish list of documented procedures
(define* (print-docs)
"Print a list of documented procedures"
(hash-table-walk *documentation-hash-table*
(lambda (key val)
(printf "~a => ~a~n ~a~n~n" key (first val) (second val)))))