[plt-scheme] format string with named parts

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Tue Feb 9 22:31:25 EST 2010

In Python, you can do

"%s %s %s" % "a", "b", "c"

and the % operator (for string interpolation) will translate that to

"a b c"

This is almost identical to the PLT Scheme

(format "~a ~a ~a" "a" "b" "c")


"a b c"

In Python, you can also do:

"%<1>s %<2>s %<3>s" % {"1": "a", "2": "b", "3":"c"}

where the {...} bit is a hash map of "1" to "a", "2" to "b", etc., and
this will be evaluate to

"a b c"

as expected. The obvious advantage of this is that you can switch
around the order of the pieces in the formatted string and since
they're named, each piece will end up where it's supposed to be.

Does PLT Scheme have anything similar, where you can name the parts of
a formatted string and fill them in using either a #hash or the
current environment or something? The web-server has templates that do
this, but the templates seem to involve a lot of overhead that I don't
think I need.


Posted on the users mailing list.