Eugene Burmako wrote:
Sure macros can do whatever they wish, including parsing text into ASTs. However the point about unification of splicing syntax for the sake of IDE support still stands.
I think bart meaning was that "some string"expr"other string" is
illegal in scala. but if the parser is aware of string
interpolation, then "${some("expr")}" is parsed so the inner
quotes are taken to part of the ${} expression.
What SIP-11 offers is a standard framework for string interpolation. It claims the $foo and ${expr} syntax and gives it a standardized meaning. If we went with only macros then everyone would invent their own interpolation syntax.
I would wait until macros stabilize before putting any references to them from std lib.
I was only saying that the need for scala"..." interpolations is less than before we knew about reify. There is a small but very powerful argument for string interpolation as a primitive: In the interpolated string id"..." escape sequences are left uninterpreted, unlike for normal string literals "...". This means the following works as expectedxml"<result> ${ root \ "title" } </result>"whereas in"<result> ${ root \ "title" } </result>".xmlyou'd get a lexical error because of the embedded "\". This, of course, would be unacceptable.Cheers- Martin
I also told about triple quotes to Martin yesterday, and he mentioned that this still doesn't rule out IDE problems. What IDE problems do I refer to? We'd like to be able to click through expr in "hello $expr!".s. Currently that'd be very hard to implement. Hard, but possible. What is a real killer though is getting autocompletion to work here: "hello $exp[_]" (where [_] points to the current location of cursor). That'd require a sophisticated macro <-> IDE protocol, which would be a good, but a time-consuming thing to implement.
Thanks Martin, I see -- also the quotes, which Bart and Ittay pointed out. What about """<result> ${ root \ "title" } </result>""".xml though? This is already common practice for "".r regexes.
My example (not using macros yet) currently parses the following:
I don't see how that is ever going to work with the interpolation indicator at the end. It certainly doesn't parse as a normal string when I remove just the first 3 letters.
In an overwhelming number of language, including Scala, a.b means "b belongs to a", or "b is subordinate to a". A.this follows this convention. S."foo" does not, and actively subverts the user's expectations.
This isn't an improvement on the SIP.
I fully agree,
But since this is the debate mailing list, and I find the s"" notation aesthetically unappealing, I wanted to suggest something else:
${"hello $world} or, if curly braces aren't good, then $"hello
$world"
the use of $ is just reusing the same symbol used inside the string interpolation. the use of {} implies a scope of operating on the strings. maybe in the future stuff like ${"foo", "$bar"} will be possible or:
${
val something = readName()
"hello $something"
otherinterpolator{"a string"}
Something I really dislike about s"hello $world!":
This syntax glues two elements (s and a string) without the option of
adding whitespace. I think this would be the only place in Scala where
that would happen.
What do we do with other interpolators?
But postfixed, not prefixed. I find the idea interesting, particularly
given how it applies over numeric literals. Making NNNkm turn into
IntContext(NNN).km would come in handy indeed! The problem is that it
would be harder on the parser, but I think it is worth serious
consideration.
+1 for breaking source compatibility once to be more consistent (also with other languages, which is nice for newcomers)
Of course, this improvement could deprecate the ugly and inconsistent inheritance from Java to express octals and hexadecimals ("0037", "0xA12", etc.)
To think about it, the main reason for string interpolation was to make the code like `"I am " + name + "!"` easier to write and read, and I just don't believe that turning strings into a way of writing some other languages inside Scala has anything left to do with that reason. IMO it's an example of straying way too far and losing the original cause.