[racket] identifier used out of context error when making my own object-copy

From: Greg Hendershott (greghendershott at gmail.com)
Date: Fri Apr 18 23:45:45 EDT 2014

Although I have hardly any experience with racket/class, and I'm not
very knowledgeable about how Racket structs are implemented, this got
me curious to look at how struct-copy is implemented.

First, your macro appears to be trying to work around the problem that
`get-field-names` only makes sense at runtime (when given some
particular object at runtime) -- but your macro is at compile-time.
That's probably why you tried the nested `(with-syntax #'(
(with-syntax (eval-syntax #'(  )))))`.

> And also, is there another version of field-names that takes a class instead
> of an object, because I think that will create another problem when I get to
> the last test (with not-really-chum).

`class-info` looks promising for that. If only you could get a
`class?` at compile time. But I haven't figured out how.

Racket struct identifiers have a meaning both at run time (as a
constructor) and at compile time (as a transformer binding to struct
info):

"5.7 Structure Type Transformer Binding

The struct form binds the name of a structure type as a transformer
binding that records the other identifiers bound to the structure
type, the constructor procedure, the predicate procedure, and the
field accessor and mutator procedures. This information can be used
during the expansion of other expressions via syntax-local-value."

As a result, struct-copy can use syntax-local-value to get the
compile-time value, and pass it to extract-struct-info, to get a list
of field identifiers.

But unfortunately a class identifier does not seem to have any
syntax-local-value at all (much less one that you could pass to
class-info).

That's my attempt at figuring it out. Hopefully one of the Racket
experts can give you an actual solution (and/or correct any of what I
wrote here).

Posted on the users mailing list.