Triple quoted strings

Jonathan Toland jonahtoland at yahoo.com
Tue Apr 29 18:40:39 PDT 2008


i apologize my previous email got sent as plain text and failed to line wrap:

i've been reading some past posts and wanted to add some supplemental input on this one and emphasize some key advantages to mirroring e4x templating syntax in triple quoted strings.  first currently beginning to work in as3 i highly regard the progress the wg has made.  es4 really has grown up into a very structured (yet still almost uniquely flexible, extensible, and dynamic) language in comparison to the tediousness of trying to scale up my js apps.

1. i have often missed string interpolation working in js although i have never missed php's (and others?) multiline strings.  i don't mind chalking that up to inexperience and an unhealthy fondness for perl but i do feel string interpolation is arguably second only to regex (which i also love) in perl's historical success which both php and more effectlively ruby (with a syntax like e4x) mimic.

2. as the poster below alluded to as3 already provides string interpolationde facto via e4x.  anywhere a string is expected i can substitute a XML literal like <>Today is {new Date.toDateString()} and the time is {new Date.toTimeString()}.</> ver batim.  this does identify a few weaknesses however:

first there is a great deal of overhead (creating the XML including the text node as child XML, translating xml entities, recognizing the type context to call toString(), forwarding toString() to the text node, and finally translating the entities back) making it potentially inefficient for any long running loop.  the vm could optimize for this but why have to?

also it seems inconsistent to define the previous content with that facility and have to redefine it normally:
//assuming xml was assigned the previous example now reassign its content
xml='The time is now '+new Date.toTimeString()+'.';
rather than the following possible employing string interpolation:
xml="""The time is now {new Date.toTimeString()}.""";

i won't contend that it's not largely syntactic sugar but the utility of string interpolation in other languages especially server side is hard to argue.  in original responses to this post it was also alluded to that exactly three characters must be escaped using e4x this way (<, {, and }, while others are handled by the vm) which i will address next.

3. using triple quoted strings for string interpolation would not only negate not having to escape new lines but any escape sequence syntax at all (including for backslashes).  literal delimiters could simply be included between braces as traditional strings e.g.:
"""this {'example """is""" NOT\xA9 {utilitarian} per'} se"""
while i may not see the utility of literal new lines i heartily concur with not having to remember to escape other characters (or recall yet another escape sequence syntax) which gets especially messy instantiating a Regexp without using literal syntax (for instance one that was built dynamically by concatenating strings).

this seems be a low bar to implement given worst case it could be simply macro processed to its current notation.  i love working with es and look forward to it becoming continually more enjoyable even if some features get deferred to es5.  i would also like to mention i emailed previously regarding a function/method interceptor/sequence syntax but didn't consider until the following day it would also benefit from proper tail calls which are already being pursuing and would alleviate painfully deep stack traces from methods with long inheritance chains.

~jon

----- Original Message ----
On 06/03/2008, jeff.ecmascript at tanasity.com
<jeff.ecmascript at tanasity.com> wrote:
> If I understand the motivation for triple quoted strings, it's to allow
>  multiline strings with inverted commas and quotes within them, and to
>  allow quotes and inverted commas within those substrings, all without
>  requiring a continuation marker.
>
>  PHP has a structure that's used for this sort of thing, which works
>  quite well and is used when you have a large block of text tobe used as
>  a string. As an example of when this is used, commonly, emails that are
>  constructed in code use this technique.

The interesting thing is ECMAScript E4X extension already allows to
enter multiline strings like in:

var i = 10;
var str = <x>arbitrary
multiline text that can embed expression
{i * 2} references</x>.toString();

The triple quota proposal would introduce significantly less powerful
mechanism for embedding the strings.





      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080429/30848ff2/attachment-0002.html 


More information about the Es4-discuss mailing list