Just a quick try not using @-exps. Does something like this look good?<br><br>#lang scheme<br><br>(define (py-format str couples)<br> (regexp-replace*<br> "~<([^>]*)>([aAsSvVeEcCbBoOxX])"<br> str<br>
(lambda(all key str-format)<br> (let ([key-val (assoc key couples)])<br> (if key-val<br> (format (string-append "~" str-format) (second key-val))<br> (error "Key not found in py-format: " key))))))<br>
<br>(py-format "~<x>a ~<y>a ~<z>s" <br> '(("x" "ola")<br> ("y" (hey "hey"))<br> ("z" "salute")))<br>
<br>; "ola (hey hey) \"salute\""<br><br><br><br><div class="gmail_quote">On Wed, Feb 10, 2010 at 17:10, Todd O'Bryan <span dir="ltr"><<a href="mailto:toddobryan@gmail.com">toddobryan@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On Tue, Feb 9, 2010 at 10:40 PM, Eli Barzilay <<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>> wrote:<br>
><br>
> Basic output:<br>
><br>
> #lang at-exp scheme<br>
> (require scribble/text)<br>
> (define foo "FOO")<br>
> (define bar "BAR")<br>
> (output @list{@foo and @bar})<br>
><br>
> (It's easy to make it return a string instead, I just didn't provide<br>
> another function (or a keyword argument or something) because there<br>
> was no need and I didn't see any interface that was obviously better.)<br>
><br>
> This is using the same functionality that the web server templates are<br>
> using, but you don't need the extra overhead of using the web server<br>
> or separate files. Here's how you'd do it:<br>
><br>
> #lang scribble/text<br>
> @(define foo "FOO")<br>
> @(define bar "BAR")<br>
> @foo and @bar<br>
> @(define (choose x y) @list{@x before @y or @y before @|x|?})<br>
> @choose[foo bar]<br>
><br>
<br>
</div>The nice thing about the Python version is that you can just have a<br>
string with placeholders for values you're going to include later. Am<br>
I correct that I really need to write a function (like choose above)<br>
that expects the values I want to go into the string so that the<br>
@-exprs don't get evaluated before they have values?<br>
<br>
Obviously, that's not much more difficult, but my brain just didn't go<br>
there automatically. Clearly, I need to spend more time programming in<br>
Scheme. :-)<br>
<font color="#888888"><br>
Todd<br>
</font><div><div></div><div class="h5">_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
</div></div></blockquote></div><br>