There is a bunch of inconsistencies and redundancy around string literals and interpolations that I think can be cleaned up and allow for a more consistent and simpler language.
Single and triple quoted strings differ in two ways: how escape sequences are handled and whether they accept new line literals.
Single and triple quoted interpolations differ only in the literal newlines. Because the interpolator decides on how escapes are handled and the interpolator doesn’t have access to whether the input was single or double quoted, it can’t differentiate between the two even if it wanted to.
A first observation is that there isn’t much of a reason not to let single quoted strings and interpolations contain newlines. It would take something that’s now a syntax error and make it in what is the obviously intended thing. It departs from how Java handles things, but if you go in thinking things work as in Java, the worst that could happen is you’re pleasantly surprised.
It would also be sort of nice if interpolations did know whether or not they are single quoted or triple quoted. They could then decide to handle escapes differently between single and triple quoted interpolations, eliminating a potential source of surprise.
With that, you could make an interpolator that works like the s
interpolator when single quoted and like the raw
interpolator when triple quoted. A string literal only differs from such an interpolation in how $
is handled.
As a bonus point, the added value of string literals when you already have interpolations becomes pretty small. That was remarked years before already by the inimitable Som Snytt, who suggested expressing string literals as the apply
interpolator: “foo” would be shorthand for apply."foo"
which would produce the string foo. Hopefully I didn’t butcher his ideas too horribly.
If fixing the mentioned warts is worth the effort, would this be the route to go, without the bonus point? If it is, what objections would there be to the bonus point?