Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2012 22:07
What would you like to do?
Sample Racket Docstring Pseudocode
;;Basic format; will create definition normally and ignore docstring entirely
(define-syntax autodoc (syntax-rules (define) [(_ docstr (define (name arg ...) body ...)) (define (name arg ...) body ...)])
;;Simple expanded example; will create definition and also print docstring each time function is called
(define-syntax autodoc2 (syntax-rules (define) [(_ docstr (define (name arg ...) body ...)) (define (name arg ...) (begin (print docstr) body ...))]))
;; Function definition
(autodoc "Function that increments numbers"
(define (my-incr x)
(+ 1 x))
(autodoc2 "Function that increments numbers"
(define (my-incr2 x)
(+ 1 x))
;; (my-incr _) and (my-incr2 _) can now be called normally
Copy link

kazzmir commented Sep 5, 2012

(define-syntax autodoc (syntax-rules (define) ([_ docstr (define (name arg ...) body ...)](begin %28proc-doc name any docstr%29 %28define %28name arg ...%29 body ...%29)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment