On Thu, Apr 7, 2016 at 4:13 PM, Rickard Andersson < rickard.m.anders...@gmail.com> wrote:
> > What have you used them for? > > https://github.com/GoNZooo/gonz/blob/master/gonz/define-test.rkt > > It's a macro that allows me to bundle expected inputs with expected > outputs for those inputs together with a contract definition, meaning > I have a tighter coupling of test-cases together with definitions of > functions without a bunch of `(module+ test ...)`. > That's a neat example, both as motivation for those asking "why macros?" and folks like me who want to get better at writing them. For a bit of learning-by-doing I was able to easily change Rickard's macro to get a different surface syntax that correctly processes: (define/cti (square2&add x y) contract: (integer? integer? . -> . integer?) tests: [2 3 -> 13] [1 2 -> 5] [-4 4 -> 31] implementation: (+ (expt x 2) (expt y 2))) Further challenges: - allow the "contract:" and "tests:" sections to be blank, but print a warning - add handling for default, keyword and rest parameters Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.