PEP 750: Tag Strings for Writing Domain-Specific Languages
discuss.python.org
PEP 750: Tag Strings for Writing Domain-Specific Languages
1–10 of 99 posts
Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#2Also the scoping rules of this are a special case which doesn't appear in regular Python code so far: "The use of annotation scope means it’s not possible to fully desugar interpolations into Python code. Instead it’s as if one is writing interpolation_lambda: tag, not lambda: tag, where a hypothetical interpolation_lambda keyword variant uses annotation scope instead of the standard function scope." -- i.e. it's "as if you wrapped all interpolation expressions in a lambda: , except it uses different scoping rules".
Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#3Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#4Instead, why not add a single new string prefix, like "l" for "lazy"? So, f"hello {name}" would immediately format it while l"hello {name}" would produce an object which contains a template and the captured variables. Then their example would be called like: greet(l"hello {name}").
Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#5I have to admit that at first glance I don’t like this. These seem to be essentially normal str -> Any functions, with some naming limitations due to the existing string prefixes special-cased in the language. I don’t feel like adding this additional complexity is worth being able to save two parentheses per function call.
Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#6It just doesn't seem worth it to define a whole new thing just to abstract over a format() function call. The laziness might be interesting, but I feel like "lazy strings" might be all that's needed here. Laziness and validation (or custom string formatting logic) are separate concerns and should be separated.
Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#7From the article: """
~CURL[curl https://catfact.ninja/fact]
|> Req.request!()
This is actual code; you can run this. It will convert the curl command into a Req request and you will get a response back. This is really great, because we have been able to increase the expressiveness of the language.
"""Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#8Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#9I have to admit that at first glance I don’t like this. These seem to be essentially normal str -> Any functions, with some naming limitations due to the existing string prefixes special-cased in the language. I don’t feel like adding this additional complexity is worth being able to save two parentheses per function call.
html() is not going to be equivalent.
Re: PEP 750: Tag Strings for Writing Domain-Specific Languages
#10I have to admit that at first glance I don’t like this. These seem to be essentially normal str -> Any functions, with some naming limitations due to the existing string prefixes special-cased in the language. I don’t feel like adding this additional complexity is worth being able to save two parentheses per function call.
At the risk of riling some people up, this smells like Perl. Some poor Python user comes across
greet"Hello {user}"
and there isn't even so much as a symbol they can search for on the internet, just an identifier smashed into a string.But I guess Python and I parted ways on this matter quite a while ago. I like to joke about Katamari Dama-C++ but Python is starting to give it a run for its money. C++ is still in the lead, but Python is arguably sustainably moving more quickly on the "add more features" front.