[plt-scheme] create complex object @ compile time but made available @ run time?
On 6/13/07, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
>
>
> > The problem here is not that it is a complex object, but that
> > structure definitions are generative - it would have worked
> > if you used vectors. Back to the structure problem. To quote the
> > documentation:
>
> > "Each time a define-struct expression is evaluated, a new structure
> > type is created with distinct constructor, predicate, accessor, and
> > mutator procedures."
Thanks for the great explanation Jens - this makes great sense - but is
there a way to prevent struct being evaluated twice, once for (require) and
once for (require-for-syntax)? In the example you cited the double eval is
clearly intended because each define-struct is enclosed lexcially and it
makes sense that they are different structs (like enclosed lambda &
variables are different), but IMHO (require-for-syntax) and (require)
evaluate the same code twice is _surprising_ (I thought it's more like
"importing" names to the transformation environment) - love to hear your and
others' take on whether this is expected.
One solution is to calculate the values at expansion time, and
> then expand to (create-foo val1 ...).
This is how I currently have it (but my code have multiple nested struct
creations, which makes it difficult to fully leverage expansion time) -
until I thought - why not try to see if the object(s) can be generated in
compile time and return to run time... close but not quite :)
Very appreciated! ;) Thanks,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070613/91032cbb/attachment.html>