That makes sense.  Thank you, Rickard.

On Wed, Apr 6, 2016 at 11:13 PM, Rickard Andersson <
rickard.m.anders...@gmail.com> wrote:

> > What have you used them for?
>
> While it's certainly not the most impactful macro in the world, I was
> pretty pleased with being able to do this:
>
> 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 ...)`.
>
> > What do they do that a function couldn't?
>
> In this case we're actually generating the `(module+ test ...)` entries
> based on the lists inside the macro, but then simply appending these to
> our generated code, meaning they won't be defined in a function (which
> they can't), but rather added as if we were doing it manually.
>
> The manual variant for the first example in this file would look as
> follows:
>
> (define/contract (square x)
>   (integer? . -> . integer?)
>   (expt x 2))
>
> (module+ test
>   (check-equal? (square 2) 4)
>   (check-equal? (square 3) 9)
>   (check-equal? (square 5) 25))
>
> We're skipping straight to defining inputs and outputs, only because we
> are using macros.
>
> > What are good times to use them
>
> In this case I wanted to succinctly define test cases for functions and
> for this to be tighter coupled to function definitions, but you can't
> call `module+` while inside a function, so the only real solution is to
> lift that content outside the function definition.
>
> > ... what are their drawbacks?
>
> The obvious drawback here is that this macro is next to useless for
> anyone else when they stumble upon it. When you have an actually useful
> macro (I hesitate to call this one universally useful, though I like it
> myself), this is solved by great documentation facilities, like
> Scribble, as well as good macro constructs that will help you guide your
> user through proper usage.
>
> On Wed, Apr 06, 2016 at 05:19:05PM -0700, David Storrs wrote:
> > Hi folks,
> >
> > Macros are one of the biggest features that people list as the advantages
> > of LISP / Scheme, and I don't really understand them.  I get the basics
> --
> > they can create new code structures -- but not the implications  What
> have
> > you used them for, and what do they do that a function couldn't?  What
> are
> > good times to use them, and what are their drawbacks?
> >
> > Dave
> >
> > --
> > 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.
>

-- 
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.

Reply via email to