On Wed, Feb 10, 2010 at 11:17 AM, Todd O'Bryan <span dir="ltr"><<a href="mailto:toddobryan@gmail.com">toddobryan@gmail.com</a>></span> wrote:
<div> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">I wasn't clear. I need to make the format strings before I'm ready to
<div>plug in the named values. In Python, they're just strings, so there's</div>
<div>no problem creating them before you have the values ready to insert,</div>
<div>but since @-exprs are really code, you have to hold off evaluating</div>
<div>them until you have the values ready to plug in.</div>
<div> </div>
<div>Either using a lambda-expression or figuring something out like</div>
<div>Laurent suggested is not hard, once you think about doing it. My</div>
<div>biggest problem seems to be not being aware exactly which tools I have</div>
<div>in my toolbox and, even when I know there's a tool in there, not</div>
<div>realizing it's good for the task at hand.</div></blockquote>
<div> </div>
<div> </div>
<div>Some of the tools live on planet ;) For example - bzlib/template provides such capability. There might be others as well. </div>
<blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
<div>> (require (planet bzlib/template))</div>
<div>> ;; pass in pairs of key & values to iqs - note order does not matter</div>
<div>> (iqs "Hello, $name, $question?" `(question . "how are you") `(name . "Todd"))</div>
<div>"Hello, Todd, how are you?"</div>
<div>> ;; you can change the escape char too via iqs-symbol-start - let's change it to % instead of $</div>
<div>> (parameterize ((iqs-symbol-start #\%))</div>
<div> (iqs "Hello, %name, %question?" `(question . "how are you") `(name . "Todd")))</div>
<div>"Hello, Todd, how are you?"</div>
<div>> ;; if you do not pass in the value it prints out the original placeholder <br>> (iqs "Hello, $name, $question?" `(question . "how are you"))<br>"Hello, $name, how are you?"<br></div>
</blockquote>
<div class="gmail_quote">On Wed, Feb 10, 2010 at 11:29 AM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:
<div> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im"> </div>I consider the python thing a hack, which is really compensating for
<div>*not* having a proper string interpolation thing. Perhaps a more</div>
<div>explicit way to see the hack is that the hash table is essentially a</div>
<div>kind of a namespace thing, which is orthogonal to the namespace your</div>
<div>code is using. I guess that you could claim that it's less of a hack</div>
<div>in python since you can reify the current namespace as a hash table</div>
<div>anyway (and perhaps that's a common idiom?).</div></blockquote>
<div> </div>
<div>IMHO the pattern comes up more often when you need `format` but with named instead of ordinal arguments, and when you might need to custom handle the non-existence of named argument (i.e. a default value). </div>
<div> </div>
<div>
<div>Cheers,</div>
<div>yc</div>
<div> </div></div></div>