Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression expansion within a string #284

Open
nyuichi opened this issue Nov 25, 2013 · 6 comments
Open

expression expansion within a string #284

nyuichi opened this issue Nov 25, 2013 · 6 comments

Comments

@nyuichi
Copy link
Member

nyuichi commented Nov 25, 2013

The syntax may subject to change.

var num = 42;

var str = """
abc
#{num}
def
""";
@gfx
Copy link
Member

gfx commented Nov 26, 2013

Looks good to me except for the symbols. Because I'd like to use it in single-line string literals, the quote symbols must not be double quotes or single quotes. Back quote (`) is a candidate; triple backquotes are used for code sections in markdown, though.

In addition, we have reasons to avoid # for interpolation: # is used for comments in some programming languages and also used for level-1 header in markdown, which might be confusing, so we'd better to use another symbol, e.g. $.

@nyuichi
Copy link
Member Author

nyuichi commented Dec 2, 2013

@gfx

Back quote (`) is a candidate; triple backquotes are used for code sections in markdown, though.

So you mean you like to write like this?

var str = "abc `{num} def";

In addition, we have reasons to avoid # for interpolation: # is used for comments in some programming languages and also used for level-1 header in markdown, which might be confusing, so we'd better to use another symbol, e.g. $.

I don't prefer $. It's too perlish.

@gfx
Copy link
Member

gfx commented Dec 2, 2013

No, I mean:

var str =`abc ${num} def`;

And $ is not from Perl, but from shell script. In fact, the use is more alike from shell's.

@kazuho
Copy link
Member

kazuho commented Dec 3, 2013

Re quote, +1 to using '`'.

Re substitution marker, IMO we should choose a character that is (or will become) familiar to ECMAScript programmers. So if the Quasi-literal of ES5 is going to use '$' then we should use it, or if not, we should use '#' (since that is the character used by CoffeeScript and TypeScript?).

@gfx
Copy link
Member

gfx commented Dec 3, 2013

TypeScript does not have string interpolation; there is a discussion found in ITS, though: https://typescript.codeplex.com/workitem/19

ES6 is also considering to use $ http://wiki.ecmascript.org/doku.php?id=harmony:quasis ; I don't know it very well.

Dart also uses $ for interpolation: https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#strings

I gues this is because # is used for location hash and CSS selectors so not suitable for HTML applications.

@kazuho
Copy link
Member

kazuho commented Dec 3, 2013

If the majority are heading towards using '$' then we should jump on the bandwagon as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants