On Jan 5, 5:27 am, MonkeeSage <MonkeeS... / gmail.com> wrote:
> On Jan 3, 7:15 am, scoot... / hotmail.com wrote:
>
>
>
> > > Why do you need a
> > > different syntax?
>
> > > Regards,
> > > Jordan
>
> > It's not a dire need, but it would definitely be useful. For example,
> > suppose you are constructing a string that generates ruby code. You
> > will need a way to tell the parser that #{foobar} is no longer
> > intended as a variable placeholder.
>
> > You could, of course, change the entire string into an uninterpolated
> > string, but that eliminates the ability to specify variables entirely.
>
> > Just to let you know this is not an original idea that I cooked up out
> > of thin air, see how Python supports this feature in:
>
> >    http://www.python.org/dev/peps/pep-0292/
>
> > and search for the text:
>
> >     define a delimiter character other than '$'
>
> > ALTERNATIVE QUESTION:
>
> > I've used ERB before, does it enable you to specify alternate syntaxes
> > for the variable placeholders? Template::Toolkit (as an example) does
> > allow this, if you want more details on what I am asking about, take a
> > look at:
>
> >    http://template-toolkit.org/docs/manual/Syntax.html
>
> > Thanks for your responses so far.
>
> Hmm...what about using %q{} or escaping "#"? You can emulate the
> python Template class (which I have never actually used in live python
> code, since % has always worked for my needs); but since it will be
> slower (benchmark Template.substitute against % in python), and you
> can do the same thing in different ways, it seems pointless to me.
> But, for completeness, here is an example:
>
> class Template < String
>   def substitute(context=nil)
>     if /@\{(.+?)\}/ =~ self
>       self.gsub("@{#{$1}}", eval($1, context))
>     else
>       self
>     end
>   end
> end
>
> blah = "foo"
> t = Template.new("Hello @{blah}").substitute(binding)
> p t # => "Hello foo"
> t = Template.new("Hello world").substitute
> p t # => "Hello world"
>
> Regards,
> Jordan

Yes, PEP292 Template strings are probably rarely ever used in
production, or even at all,
(that's speculation here, but doubtless accurate) and the performance
issue
and other points you mentioned are of course well stated. There
are ,however,
instances where this specific feature is actually very useful and a
huge
time-saver.

Nevertheless, thanks for the responses and overview.