[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] string formatting notation




On 22 Dec 2017, at 17:42, brianlheim@xxxxxxxxx wrote:

It is simply a new kind of literal. Nothing more, nothing less. f is not a method in this design, and nothing requires it to be. I didn't make that clear originally, sorry.

"this is a string" is a literal
3 is a literal
f"this is a ${object}" would be a new kind of literal, just like
u"abc" is a Unicode string literal in C and C++ and
r"\n" is a raw string literal in Python and
0x6 is a hexidecimal number in many languages

'f' in the context of f-strings is a literal prefix that qualifies the interpretation of the literal.

> Would this look up instance vars in the local scope?

I think so, it would be evaluated at runtime. I can imagine that under the hood it would be implemented as a new literal type that compiles to a normal string literal + call to `format`.

Well, seems more like syntactic sugar for a literal and a method call. A literal has a literal representation in code.

But semantics…

S.