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

[sc-users] Re: string formatting notation



ddw_music wrote
> ... it just occurred to me
> that you could do a proof of concept now, with no changes to the lexer,
> using the preprocessor. That is, change the code string
> 
> f"a = {{a}}"
> 
> into
> 
> "a = %".format(a)

See the attached scd for an initial stab at it. Limited testing, but I did
check:

- Nested f"" strings convert to valid SC syntax ;)  It ain't necessarily
pretty (a format call within a format call), but it accurately reflects the
input structure and evaluates properly.

- A closing f at the end of a string literal doesn't confuse the converter:
"abcdef" is OK.

- Unclosed braces within an f"" throw an error, rather than generate wrong
syntax to pass to the interpreter.

- 'abcdef"xyz', correctly, does not trigger f"" parsing.

So, Merry Christmas ;)  It was kind of fun and didn't take that long. (But,
the main reason why I could do it fairly quickly is, oh, I'd guess 100-200
hours' work on the preprocessor for my live-coding dialect -- I have a lot
of practice scanning code strings in SC...)

Again, this is not a "solution." It's a prototype. I've expressed skepticism
about embedding code into strings -- but, to be fair, I should try it for a
while and see if I like it. To be honest, when James McCartney introduced
|args| instead of "arg args", I needed to try that for myself too... and in
that case, I came to feel (pretty quickly) that "10.do { |i| ... }" was less
noisy than "10.do { arg i; ... }". So, who knows? I might end up liking it.

hjh

PS I didn't try to be compatible with any other preprocessor -- exercise for
the user.

string-interpolation.scd
<http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/file/t149410/string-interpolation.scd>  



--
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/