The "Introduction" from the syntax/parse docs (
http://docs.racket-lang.org/syntax/stxparse-intro.html), is very good in
the spirit of the Racket Guide and also explains why you want to use
syntax/parse. Between that and the "Examples" section, I found I could
handle many of the cases I wanted to without needing to dive into the more
intimidating parts of the documentation for quite a while.

-Philip

On Fri, Feb 23, 2018 at 8:13 AM, Paulo Matos <pmatos@linki.tools> wrote:

>
>
> On 23/02/18 15:07, Philip McGrath wrote:
> >
> > I also used syntax-parse to conveniently check that n really is a
> > nonnegative integer literal, though of course you could write such a
> > check with syntax-case if you really wanted to.
> >
>
> Thanks for the code snippet which goes in the same direction as
> Matthews, except it uses syntax-parser, which I have never looked at
> before. Should probably look for a good intro to it.
>
> > Note that this generates quite a lot of code. I'm assuming there's a
> > good reason you want to do this with a macro and not a function (perhaps
> > using with-check-infoto enhance failure reporting), but that's certainly
> > something you'd want to consider if you haven't.
> >
>
> That's true, thanks for pointing it out. I only just noticed you could
> generate test-suites and test-cases at runtime with make-testcase and
> make-testsuite. Therefore I will actually be doing this without a macro.
> However, it's always very useful to attempt this macro katas. :)
>
> Thanks,
>
> > -Philip
> >
> > On Fri, Feb 23, 2018 at 7:11 AM, 'Paulo Matos' via Racket Users
> > <racket-users@googlegroups.com <mailto:racket-users@googlegroups.com>>
> > wrote:
> >
> >     Hi,
> >
> >     I am trying to get a macro working to generate an automatic
> testsuite. I
> >     have shrank my example to:
> >     #lang racket
> >
> >     (define-syntax (gen-testsuite stx)
> >       (syntax-case stx ()
> >         [(_ n)
> >          #`(test-suite
> >             "Automated suite"
> >             #,@(for/list ([i (syntax->datum #'n)])
> >                  #`(test-case
> >                     (format "Test number ~a" i)
> >                     (check = i i))))]))
> >
> >     (require rackunit
> >              rackunit/text-ui)
> >
> >     (run-tests
> >      (gen-testsuite 100))
> >
> >     This should generate a test-suite that can then be wrapped in
> run-tests.
> >     It should example to something like:
> >     (testsuite
> >        "Automated suite"
> >        (test-case "Test number 1" (check = 1 1))
> >        (test-case "Test number 2" (check = 2 2))
> >        (test-case "Test number 3" (check = 3 3))
> >        ...)
> >
> >     This fails because the i in the body of the test case does not exist
> at
> >     run-time. I understand why this is failing. However if I try to
> replace
> >     the i by #,(syntax->datum #'i) it also fails. My feeling is that I
> need
> >     to introduce a new template variable, which I would generally do with
> >     with-syntax however I am not sure how to integrate this with the
> >     for/list expression.
> >
> >     Regards,
> >     --
> >     Paulo Matos
> >
> >     --
> >     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
> >     <mailto:racket-users%2bunsubscr...@googlegroups.com>.
> >     For more options, visit https://groups.google.com/d/optout
> >     <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
> > <mailto:racket-users+unsubscr...@googlegroups.com>.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> Paulo Matos
>

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