On Sat, May 26, 2018 at 3:11 PM, Alexis King <lexi.lam...@gmail.com> wrote:

> This isn’t a direct answer to your question, but as Matthias notes, my
> struct-update package already implements a macro that generates
> functional setters from structure definitions. Here’s a link to the
> documentation:

Offffffff *course* there is.  Lord know, why should I have an original idea
now?  :P

>     http://docs.racket-lang.org/struct-update/index.html
> Of course, that isn’t especially helpful if your goal is to get better
> at authoring macros, not just generate functional setters. For that, you
> might find the (short) source code of struct-update helpful, located
> here:
>     https://github.com/lexi-lambda/struct-update/blob/
> 8ce456cde8764ae27c348123ec9e01e76826d536/struct-update-lib/
> struct-update/main.rkt

Yes, thank you, this helps.  I hadn't thought about superclass fields.

> Admittedly, your make-functional-setter function does a bit more than
> define-struct-updaters, since it allows for a wrapper function. So I’ll
> also give some brief answers to a few of your unrelated questions.

I think we take a different approach -- struct-updaters always specifies a
contract of (-> struct-id? any/c struct-id) whereas make-functional-setters
offers the option to not have a contract or to specify whatever contract
you want.  I'm a firm believer in the idea that you should be allowed to
shoot yourself in the foot if you want the ability to do so.

> > On May 26, 2018, at 10:46, David Storrs <david.sto...@gmail.com>
> > wrote:
> >
> > A) Is there a way to test if a syntax class has a particular attribute
> > before trying to use it?
> Yes, use the attribute form. If x is an optional attribute, (attribute
> x) will be #f if the attribute was not bound and the value of the
> attribute if it was bound. If you want, you can change the default value
> to something else other than #f by providing the #:defaults option to
> ~optional.

Handy, thanks.

> > B) Alternatively, is there a way to create a null syntax object that
> > expands to nothing?  Not (void), not "", literally nothing.   Then I
> > could have each pattern bind all the attributes via #:with and just
> > have some of them be blank.
> Not in an arbitrary context. In a definition context, (begin)
> effectively expands into nothing, since begins are spliced into the
> enclosing context, but in an expression context, you can’t have
> something that expands into nothing.
> That said, it sounds like what you might actually want is the template
> and ?? forms from syntax/parse/experimental/template. This allows you
> to write something like this:
>     (template (foo (?? x)))
> The above will be like #'(foo x) if (attribute x) is non-#f, but if it
> is #f, it will be like #'(foo). In Racket 6.12 and earlier, you must use
> the template form for ?? to work, but in Racket 7 and later, ?? will
> also work with the ordinary syntax (aka #') form, so if the word
> “experimental” spooks you, don’t worry about it too much.
> Alexis
This is really helpful, thank you.

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