michaelmmacleod
2019-6-7 02:20:57

Does anyone know if there exists a package that lets me write functions and their documentation “at the same time”? For example, I wrote a macro that lets me do this: @with-doc[ (define (factorial [n : natural?]) : natural? (if (= n 0) 1 (* n (factorial (sub1 n)))))]{ Returns the factorial of @racket[n]. } The macro is here: (define-syntax (with-doc stx) (syntax-parse stx [(_ ((~literal define) (name:id [arg:id (~literal :) arg-contract:expr] ...) (~literal :) return-contract:expr body:expr ...+) documentation ...) #'(begin (defproc (name [arg arg-contract] ...) return-contract documentation ...) (provide (contract-out [name (-> arg-contract ... return-contract)])) (define (name arg ...) body ...))])) Of course, there’s a lot of things that could be improved with this implementation of with-doc. I was searching online for similar functionality, but couldn’t find it anywhere. Does anyone know if something like this already exists?


samth
2019-6-7 02:24:40

@michaelmmacleod search for proc-doc


michaelmmacleod
2019-6-7 02:29:37

@samth Thanks! That’s just what I was looking for.