[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Re: string formatting notation
*Question:*
Will there be a limit on the complexity of the expressions to be
interpolated?
"The answer is % %".format(
in(freq * theta + phase).asStringPrec(4),
if(0.5.coin) { "units" } { "items" }
)
vs
f"The answer is \(sin(freq * theta + phase).asStringPrec(4)) \(if(0.5.coin)
{ "units" } { "items" })"
I could imagine stylistic or best-practice recommendations to avoid the
latter usage, but I'm not sure how one would design a compiler to forbid
unclear use of string interpolation.
Also, will there be a policy on quotes-within-quotes? The Python PEP
mentioned earlier does have such a policy: the Python tokenizer forbids it,
so you just can't do it. I know from my cll live-coding framework that this
f"" example lexes easily from left to right: the \( delimiter could "reset"
the open/close quote status so that the next quote is open, and the matching
) would reset it the other way. But, in hindsight, I wish I had used proper
open/close delimiters.
Either way, this f"" example illustrates why I tend to favor program-flow
focus. `"Upper limit = \(upper)"`, a trivial case, is easy to read, but when
you scale the expressions up to higher degrees of complexity, legibility
disappears and it becomes much harder to tell which parts of that expression
will be evaluated and which are literal text. But with .format(), there is
absolutely no question about it (and Scott is correct, .format() will be
much MUCH easier to explain to students).
For fun, you could nest f"" strings.
f"What the \(if(0.5.coin) { "heck" } { f"\(if(0.5.coin) { "ch" } {
102.asAscii })uck" })"
Well. I'm sold. I can totally read that.
hjh
--
Sent from: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SuperCollider-Users-New-Use-this-f2676391.html
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/