Created
September 5, 2012 22:07
-
-
Save ChimeraCoder/3645946 to your computer and use it in GitHub Desktop.
Sample Racket Docstring Pseudocode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(define-syntax autodoc (syntax-rules (define) ([_ docstr (define (name arg ...) body ...)](begin %28proc-doc name any docstr%29 %28define %28name arg ...%29 body ...%29)