3 ms·
ES6's template strings can do something similar: https://github.com/erights/quasiParserGenerator https://github.com/erights/quasiParserGenerator I was disappoi
by abecedarius 10y ago
ES6's template strings can do something similar: https://github.com/erights/quasiParserGenerator https://github.com/erights/quasiParserGenerator
I was disappointed when Python added its f-strings instead.
- OJFord 10y ago> I was disappointed when > Python added its > f-strings instead. What's the difference, other than syntax? (I've only a basic familiarity with JS.)
- abecedarius 10y agoIn ES6 (and earlier, in E) you can write variable_name`string with ${expression} in it`, where the value of variable_name must be a function. The function gets called with an array of the substrings between the ${expression} parts, plus the values of the expressions. The function can return anything, including a non-string value. (So e.g. you might define dom so that dom`<p>Hello world` returns a new DOM node.) If you write just `string with ${e}` then there's a default for the variable_name part which does simple interpolation, like Python's f-strings. So it's a powerful way of embedding other languages in the host language, where f-strings are not. The quasiParserGenerator library I linked to shows some of the potential.