[plt-scheme] Idiomatic way of calling an object's accessors given dynamic method name?

From: Jacob Matthews (jacobm at cs.uchicago.edu)
Date: Mon Feb 19 17:58:51 EST 2007

On 2/19/07, Daniel Yoo <dyoo at cs.wpi.edu> wrote:

I can't help with your original question, but ...

> [...]
> I'm trying to avoid EVAL at all costs.  *grin* So there's only going to be
> a limited set of "special expression forms" between the '$' delimiters.
> In any case, since the interpretation of this is all handled at runtime, I
> can't know the accessor's name in advance, so I need some kind of
> mechanism for calling accessors dynamically.

Why is this handled at runtime?

I wrote a version of this sort of thing at one point --- a library
called quasistring (http://people.cs.uchicago.edu/~jacobm/qstr/),
which hasn't been maintained since the 20x series --- that did
everything statically. This imposed the constraint that any Scheme
code you wanted to evaluate inside a string had to appear literally in
a string constant, so something like (string-append "$ (+ 7 " " 8) $")
wouldn't evaluate to "15", but I can't imagine that you could do
anything but get yourself in trouble that way. (I know that every time
I try to do something cute like that with format strings I get burned,
anyway.) And in exchange you never have to use use eval, DrScheme can
properly color and arrow the code inside your strings, and so on.

-jacob


Posted on the users mailing list.