-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add the sm"" interpolator to the standard library. #6254
Conversation
This has been a feature available to the compiler since a0001fc (back in 2012!), but somehow never made it to the masses. It's useful, so let's put it in `StringContext` so all can enjoy its margin-stripping goodness. Rather than just copy the implementation over, I've taken the liberty of turning it into a macro. Since there are plans to intrinsify the `s""` and `raw""` interpolators in the near future, the macro emits a call to `raw""` in the form that will be expected by that transformation. Since the new interpolator can't yet be used in reflect/compiler, there's a `private[scala]` shim `sm0` for their benefit. After reSTARR, I'll change them back to the stdlib one.
I don't think "sm" to conveys the meaning well enough for a standard interpolator. We sort of Huffman code "s" and "f" as they are very common, and then we have a longer name for "raw" which is a bit more niche. By that reasoning, Another weakness of the interpolator as I wrote it is that it is hard coded to So this needs to be weighed up against the benefit from the problem which this interpolator solves (arguably surprising results when interpolated values contain newlines and the margin char on the next line, but didn't want it stripped). |
That's probably fair.
I wonder how many people use the one-arg form of I happen to like having this around, and I've put it in my own code at times. It was suggested that it might be a reasonable stdlib addition. If the detriments prove too detrimental, then so be it. |
I don't agree with retronym's comment that it must be maximally flexible in order to be maximally useful. Picking a useful interpolator name is hard. It just occurred to me this second that a suffix operator could do the stripping at compile time, |
It would be quite easy with Contextual, but that's a dependency that doesn't want to be in the standard library... There's a difference between stripping at compile-time or runtime, of course. Aside from the better performance, it might actually be more desirable not to strip margins in substituted text (that's not known at compile time). |
As a suggestion for what to call it, how about |
I provoked a gitter discussion about this, which I'm archiving here in case anyone cares that their opinions not vanish down the gitter memory hole. |
That was what originally prompted me to add |
cf #6957 following my previous comment. I was going to follow @propensive 's suggestion of |
This has been a feature available to the compiler since a0001fc (back in 2012!), but somehow never made it to the masses. It's useful, so let's put it in
StringContext
so all can enjoy its margin-stripping goodness.Rather than just copy the implementation over, I've taken the liberty of turning it into a macro. Since there are plans to intrinsify the
s""
andraw""
interpolators in the near future, the macro emits a call toraw""
in the form that will be expected by that transformation. Once it's merged, I'll add a test that the macro does indeed trigger the transformation.Since the new interpolator can't yet be used in reflect/compiler, there's a
private[scala]
shimsm0
for their benefit. After reSTARR, I'll change them back to the stdlib one.I published this locally and used it as a STARR with the compiler/reflect usages restored to
sm""
; everything seems to work fine. I've pushed up a dummy commit that does that so Jenkins can double-check.[nomerge]
commit before merge