> Since you said it’s not about typing I’d personally prefer something like "...".interpolate
For better or worse, it's impossible as a method call because of the nature of string interpolation; it requires new syntax elements of necessity. I think most people would prefer using a distinctive notation to express something that is syntactically distinct from a method call.
Again sorry if I’ve misunderstood, but why is it impossible? Quick and dirty proof in user code below. Lacking detail (I’m too lazy sorry; had to get up at 3:30 for an early flight), but shows how it could work.
var foo, varnames, string, ind; string = "foo contains {foo}”; // this sort of thing is what would go on in the interpolate method, probably as a primitive varnames = thisFunction.def.varNames; ind = varnames.indexOf(\foo); string.replace("{foo}", this.getBackTrace.vars[ind].asString);
As I say, would probably better in a primitive, but doesn’t seem like a method would be impossible. An approach using environment vars would be even easier.
For comparison, this would be similar to having to type:
13F.hex;
for `13F` to be understood as a hexidecimal literal at compile-time. Now `.hex` looks like a method call, but is really a builtin postfix that changes the meaning of the literal preceding it.
> That’s nothing new, easier to understand and remember than f”...", and matches existing conventions and style.
SC's 0x and 36r are both existing conventions here. They are nifty brief prefixes that signal a literal (numeric) type and allow things to happen at compile-time that could only otherwise be done with invoking the interpreter at runtime. To a lesser extent you could also consider 3s to be part of this convention. Whether or not we think those are good language features is another story; I'm just pointing it out since you brought up the question of language style.
The difference is that the numerical ‘prefixes’ are just an accepted symbolic notation for a number. They are still literals. (Let’s not mix up numbers and numerals.) We could also support Roman numerals if we wanted. IV could also be a literal.
What you are talking about is not a literal. 0x11 is always the same thing. There’s only one interpretation.. f”foo {bar}” is not. It could be many different strings. (Which is kind of the the point.)
So that is something new I’d say.
S. |