lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

Unify string interpolation and XML interpolation #240

Closed sasha2048 closed 3 years ago

sasha2048 commented 3 years ago

Currently:

The following, of course, doesn't work: s"Item count is {itemCount}", <span>Item count is $itemCount</span>.

The simplest solution would be to create add one more string interpolator — say, b"Item count is {itemCount}". It will have the following benefits:

  1. Similarly looking syntax with XML interpolator (e.g. handy when you're moving stuff between strings and XML).
  2. Single syntax for simple expressions and complex expressions: s"$value and then ${value+1}"b"{value} and then {value + 1}" (or, if you always use ${…}, even for simple expressions, then {…} is just cleaner).
SethTisue commented 3 years ago

The simplest solution would be to create add one more string interpolator

the use of $ to introduce interpolated items is built-in at the language level, as per https://docs.scala-lang.org/overviews/core/string-interpolation.html , so I believe you are asking for a design change to how string interpolation in general works, not merely asking for "one more string interpolator"

SethTisue commented 3 years ago

also, Scala's XML syntax has been considered legacy for a long time now and is well into the process of being phased out entirely, so I expect you would need a stronger design justification for this than just "unify with XML"

(string interpolation was added to Scala some years after XML support was added; if string interpolation had existed first, language-level XML support would probably never have been added at all)

sasha2048 commented 3 years ago

@SethTisue, thanks for explanation.

On the one hand, I liked {name} style more than $name and/or ${name}. On the other hand, I also like the idea to phase out XML support, because I feel that its syntax (in Scala) is not fully consistent per se (I even was thinking about creating a separate feature request related to that).

Probably I should close this request.

P.S. Do you know — is there another feature allowing to generate XML quickly (something quicker than just calling scala.xml.Elem constructors directly, which can be used instead of that going-to-be-phased-out language-level XML support)?

smarter commented 3 years ago

There's https://github.com/lampepfl/xml-interpolator/ but it's in need of a maintainer.