> I'm not sure whether I should have known that the #:auto value would be the 
> same object, so to speak, across all instances. Is there a bigger picture, in 
> that respect, or is it just that structs happen to work that way, and other 
> data structures might not?

A part of me just wants to blame mutable state here—this sort of thing
wouldn’t be a problem without mutation!—but of course, that is a rather
unhelpful piece of information. ;)

More usefully, this does appear to be something of an interesting quirk
about the #:auto value for structs. It’s a kind of flaw that comes up in
other languages in similar places (Python’s default arguments also
evaluate the default expression only once, causing similar behavior),
but it is perhaps unclear what the “right” behavior is. In this case, I
would probably instinctively expect the #:auto expression to be
evaluated once per field, as you did, but in hindsight the behavior
makes some sense.

Is there a bigger picture here? I don’t think so. Since struct is a
macro, there’s no way to really communicate its precise evaluation rules
except through documentation, so the docs should almost certainly be
improved here to note this kind of gotcha. Otherwise, I would probably
just second Ben’s advice and avoid #:auto in favor of your own “smart”
constructors: I have found #:auto to be less flexible than I would like,
and this kind of quirky behavior seems like a good reason to spurn it
altogether unless you’re just filling things in with #f or something.

Alexis

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