Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created September 5, 2012 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChimeraCoder/3645946 to your computer and use it in GitHub Desktop.
Save ChimeraCoder/3645946 to your computer and use it in GitHub Desktop.
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
@kazzmir
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