[racket] Dynamically get all fields of an object?

From: Johann 'Myrkraverk' Oskarsson (myrkraverk at yahoo.com)
Date: Sun Aug 18 09:19:12 EDT 2013

Hi all,

Is it possible to get hold of all fields of an object?  Not just their
names like with (field-names this) but also (or instead) the values?

Apparently, it does not work to combine field-names with get-field since
the latter is, I believe, a macro and I don't know how I can feed it a
symbol to look up.

My attempts to use (class-info this%) also failed.

What I want to do is, to dispatch a message to all fields of the current
object, whether defined in a subclass or not; assuming they are of the
right type.  Something like

  (for ((field list-of-all-fields))
    (when (is-a field thing%)
          (send field message)))

Is this possible?


Johann

Posted on the users mailing list.