[plt-scheme] format string with named parts

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Feb 10 14:17:28 EST 2010

I wasn't clear. I need to make the format strings before I'm ready to
plug in the named values. In Python, they're just strings, so there's
no problem creating them before you have the values ready to insert,
but since @-exprs are really code, you have to hold off evaluating
them until you have the values ready to plug in.

Either using a lambda-expression or figuring something out like
Laurent suggested is not hard, once you think about doing it. My
biggest problem seems to be not being aware exactly which tools I have
in my toolbox and, even when I know there's a tool in there, not
realizing it's good for the task at hand.


On Wed, Feb 10, 2010 at 1:41 PM, Eli Barzilay <eli at barzilay.org> wrote:
> On Feb 10, Todd O'Bryan wrote:
>> 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. :-)
> I'm not following the problem there.  I wrote a function just to show
> that you can, I could have had just this
>  #lang scribble/text
>  @(define foo "FOO")
>  @(define bar "BAR")
>  @foo and @bar
>  @foo before @bar or @bar before @|foo|?
> with the same output.
> The text is basically just code, so it follows the same rules.  For
> example, if you want to plug in values into (+ 1 2) later, then you
> make that into a (lambda (x y) (+ x y)) function...
> (Also, you could use promises to delay evaluation of any part, if this
> is what you're after.)
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.