[plt-scheme] format string with named parts

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Feb 10 11:10:04 EST 2010

On Tue, Feb 9, 2010 at 10:40 PM, Eli Barzilay <eli at barzilay.org> wrote:
> Basic output:
>  #lang at-exp scheme
>  (require scribble/text)
>  (define foo "FOO")
>  (define bar "BAR")
>  (output @list{@foo and @bar})
> (It's easy to make it return a string instead, I just didn't provide
> another function (or a keyword argument or something) because there
> was no need and I didn't see any interface that was obviously better.)
> This is using the same functionality that the web server templates are
> using, but you don't need the extra overhead of using the web server
> or separate files.  Here's how you'd do it:
>  #lang scribble/text
>  @(define foo "FOO")
>  @(define bar "BAR")
>  @foo and @bar
>  @(define (choose x y) @list{@x before @y or @y before @|x|?})
>  @choose[foo bar]

The nice thing about the Python version is that you can just have a
string with placeholders for values you're going to include later. Am
I correct that I really need to write a function (like choose above)
that expects the values I want to go into the string so that the
@-exprs don't get evaluated before they have values?

Obviously, that's not much more difficult, but my brain just didn't go
there automatically. Clearly, I need to spend more time programming in
Scheme. :-)


Posted on the users mailing list.