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

String interpolation needs name independence #6010

Closed
scabug opened this issue Jun 29, 2012 · 5 comments
Closed

String interpolation needs name independence #6010

scabug opened this issue Jun 29, 2012 · 5 comments

Comments

@scabug
Copy link

scabug commented Jun 29, 2012

There is no way to define a string interpolation template separately from the interpolation, nor to compose multiple templates. Thread. It was suggested by Miles that

It'd be nice if we could get that back and write something like,

 // Inferred type should be Int => String
final val template = s"""This is string $(_:Int)."""

Then all of your examples boil down to function application and/or composition.

to which eugene said "Could you submit an enhancement request for that please?", a request which I am presently fielding.

@scabug
Copy link
Author

scabug commented Jun 29, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6010?orig=1
Reporter: @paulp

@scabug
Copy link
Author

scabug commented Jul 1, 2012

@dcsobral said:
Not to be too picky, but I'd imagine the syntax would be this:

val template = s"""This is string ${_:Int}."""

In don't understand why it doesn't work, actually. It should expand to:

val template = new StringContext("""This is string""").s(_: Int)

Which is valid code.

@scabug
Copy link
Author

scabug commented Sep 24, 2013

@som-snytt said:
PR for etapolation at scala/scala#2793 was closed because of jitters.

The thread suggests more could be done with names in a StringContext, so this is not a duplicate of #7715. cmp"$smaller is smaller than $bigger"(x,y) where the cmp does the obvious computation and makes the args available to the template by name, as it were from the context local to the StringContext.

That "etapolation" coinage might be the best I ever manage; except for the "intersobralator" used by implicitNotFound.

@SethTisue
Copy link
Member

interesting. could be revived as a discussion on https://contributors.scala-lang.org

@milessabin
Copy link

Leaving a pointer to this gist here as a reminder that we once more or less had what's being requested here.

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

No branches or pull requests

3 participants