
On Sun, Jan 16, 2022 at 04:23:47PM -0800, Brendan Barnwell wrote:
On 2022-01-16 16:11, Steven D'Aprano wrote:
Do they? How are they different? You have a start delimiter and an end delimiter.
The only difference I see is that with strings the delimiter is the same, instead of a distinct open and close delimiter. But that difference is surely not a reason to reject the use of a prefix.
Well, there is a big difference, which is that the stuff between other delimiters (parentheses, brackets, etc.) is wholly constrained by Python syntax, whereas the stuff between string delimiters is free-form text, with only a few restrictions (like not being able to use the delimiter itself, or to include newlines in single-quoted strings).
Which is also wholly constrained by Python syntax, seeing as they are Python strings :-)
Whether that difference is important for your proposal I won't address right now. But it is a big difference. It also greatly affects how people view the code, since syntax highlighters will often color an entire string literal with the same color, whereas they don't typically do that for other kinds of delimited chunks, instead highlighting only the delimiters themselves.
Are any of these differences relevant to putting a prefix on the opening delimiter? If they are not, why mention them? We could also talk about the difference between the numeric value of the ASCII symbols, or the number of pixels in a " versus a { glyph, or the linguistic history of the words "quotation mark" versus "curly bracket" too, but none of these things seem to be any more relevant than whether IDEs and syntax colourizers colour "..." differently to {1, None, 4.5}. Can we bypass what could end up being a long and painful discussion if I acknowledge that, yes, frozensets are different to strings, and so the syntax is different. (Different things necessarily have different syntax. Otherwise they would be indistinguishable.) - Sets (like lists, tuples and dicts) are compound objects that contain other objects, so their displays involve comma-separated items; - string (and byte) literals are not, except in the sense that strings can be considered to be an array of single-character substrings. I thought that was so obvious and so obviously irrelevant that it didn't even need mentioning. Perhaps I am wrong. (It has to happen eventually *wink*) If somebody can explain *why* that matters, rather than just declare that it rules out using a prefix, I would appreciate the education. Hell, even if your argument is just "Nope, I just don't like the look of it!", I would respect that even if I disagree. Aesthetics are important, even when they are totally subjective. If it helps, Julia supports this syntax for typed dicts: Dict{keytype, valuetype}(key => value) where the braces {keytype, valuetype} are optional. That's not a display syntax as such, or a prefix, but it is visually kinda similar. Here are some similar syntax forms with prefixes: * Dylan list displays: #(a, b, c) * Smalltalk drops the comma separators: #(a b c) * Scheme and Common Lisp: '(a b c) and double delimiters: * Pike: ({ a, b, c }) * Pike dicts: ([ a:b, c:d ]) Not that we could use any of those as-given. -- Steve