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

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Wed Feb 21 13:09:34 EST 2007

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

Hi Jacob,

It's not be necessary at runtime if the template string is embedded 
directly in the source code.  But the major use case is going to be where 
I separate the templates outside of the source code into separate 
StringTemplate (.st) files.  Furthermore, I want to allow the user to be 
able to change those templates on-the-fly.

As far as I understand, the static approach will only work if I guarantee 
those template files won't change.  That might be a restriction that's too 
strong for the intended application.  I might want to leave open the 
possibility of a weaker notion of variable references in templates: even 
if all the variables aren't bound to values, perhaps I might want to stuff 
in a "FILL ME IN" or something like that in any unbound reference.

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

Cool!  I'll take a look at this.

It would be nice to have the best of both worlds somehow, being able to 
change templates on-the-fly but still have some static guarantee that 
variable references in the templates aren't unbound.  I get the feeling, 
though, that those are two complementary goals.  But cooperating with 
DrScheme should be something I'll can do if I restrict the templates to be 
static as in quasistring.

> And in exchange you never have to use use eval, DrScheme can properly 
> color and arrow the code inside your strings, and so on.

I should have mentioned: I'm not using EVAL now, and I won't need it.  (I 
was worried how to do simple object method calls, but my original post 
gives me that.)  At the moment, string-template.ss is an interpreter for 
the parse tree I get out of these templates.  The code lives in:


Thanks again!

Posted on the users mailing list.