I was searching for a new interpolation syntax that would use quotes
for starting/ending the interpolated part (I don't feel comfortable
putting code inside unclosed quotes...)
After contemplating some horrors like $"""str"expr"str""" or
$("str" expr "str"), I noticed that currently both "( and )" are
illegal (first because strings are not callable, second is a syntax
error). So I propose that a parenthesized expresion near a string would
imply concatenation. In other words,
"foo"(x * 3)"bar"
would be equivallent to
"foo" + str(x * 3) + "bar".
This works of course with only one side, e.g. "foo"(x) or (y)"bar" but in
longer cases it would be good style to add empty strings on either end,
e.g. ""(y)"bar". And of course it all works with single quotes too. One
of the benefits over current interpolation PEPs is that you can change the
quote type in the middle...
It is slightly more verbose (especially when interpolating into tripple
quote strings: """foo"""(x)"""bar""") but it is more readable and
understandable (just extends the current concatenation of constant
strings), allows clear nesting of strings into the expr:
"foo"('%3d' % x)"bar"
and most importantly, you never need to remember arbitrary rules where the
What do you think?
Beni Cherniavsky <cben at tx.technion.ac.il>
Awake! Awake! Fear, Fire, Foes! Awake! Fire, Foes! Awake! [Tolkien, LOTR]
Fight software patents: http://lpf.ai.mit.edu/
BTW, does somebody know what's the situation in Israel
concerning software patents?