On 14 Dec 2009, at 22:44, Mike Samuel wrote:

> http://wiki.ecmascript.org/doku.php?id=strawman:quasis
> is a strawman for a concrete syntax that enables string interpolation
> as described in
> http://wiki.ecmascript.org/doku.php?id=strawman:string_interpolation .
> 
> So far it's just an uploaded HTML file but I plan to make it more wiki 
> friendly.
> If people want to edit it, let me know and I'll put out a wiki form pronto.

First things first: the string interpolation strawman[1] is not string 
interpolation. It's LINQ (Language Integrated Query) or very similar, which 
dare I say it, is what E4X is (or attempts to be, spec bug not withstanding) 
Which isn't to say I don't think the idea has merit, it is just more than 
simply string interpolation. (When i say its LINQ - it feels very much like the 
query syntax front end for it.)

The pessimist in my would like to point out that you could (and people 
inevitably will) still say `UPDATE foo SET x=$x`. Unless i've missed something 
crucial this doesn't protect against that (as its not  a sql`UPDATE ...`. Also 
which 'sql' - there are many variants)

backticks In perl, ruby and php is all the system execute command (which I 
suspect you know) but the "where it allows interpolation though with a more 
specific meaning than macro expansion" wording isn't quite correct -- it does 
more than just interpolattion.

I really like the idea of being able to do things like |var my regexp = 
re`(?i:\w+$foo\w+)`;|

quasi-strawman.html says:
>> It would be convenient for some DSL use cases to allow LineTerminators 
>> inside code, but it is unclear how this will interact with revision control 
>> systems that rewrite newlines on checkout


If you want to use a certain form of a new line for what ever reason, it would 
probably be best to use \n. Line continuations are rather annoying to use in 
practice - if you want the literal to be split over multiple lines, and to have 
new lines in the source you end up ending every line with \n\ which is just 
ugly. Since we are already talking about new syntax, I would vote for allowing 
multi-line literals.

If you haven't yet read http://www.python.org/dev/peps/pep-3101/ (Advanced 
String Formatting) I suggest you do - its well worth a read and feels like a 
possible very javascripty solution.

One thing I'm not seeing here is a way to interpolate one quasi literal inside 
another one. I'm guessing the intent is html`<h1>$x</h1>` would html escape the 
x variable (this wasn't actually explicitly stated anywhere that I read). But 
how do you say 'x is already html, don't escape it again?' I guess this comes 
down to how do you detect and interact with quasi-literals? Do they have a new 
typeof? What methods do the instances have? How exactly to you write new quasi 
tags/types?

I can understand not having printf style formatting codes, but how would you 
suggest you format a number to 2 decimal places?

In summary:
* Quasi-Literal or string interpolation strawman? whats what?
* How do you interact with literals (in more detail)
* What quasi types would be built in?
* I would *really* like multiline literals. (akin to pythons """ operator or 
heredocs in perl and ruby)
* The metadata example - there is no other mention to metadata
* I'm not sure its worth allowing such complex expressions inside the ${} 
(brackets example)
* No printf/formatting at all might be missed

Thanks for fleshing this out in more detail - I've been meaning to write an 
email about the lack of detail in the string interpolation strawman for a 
couple of weeks.

-ash

[1]: http://wiki.ecmascript.org/doku.php?id=strawman:string_interpolation
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to