Open porres opened 3 years ago
i think that \5
is not a valid way to express a symbol 5
.
please don't get in the habit of using it. (languages like Python or C would take \5
to mean (aka the ENQUIRY character, or \u0005
).
that said, I agree that not storing the slash in the patch is a bug (like the similar reports #1166, #1083). while superficially different, i think that all these bugs would be resolved if somebody would sit down and fix the escaping logic for good.
I agree. I think we need simple, understandable escaping which works within Pd and via pdsend
and pdreceive
.
languages like Python or C would take \5 to mean � (aka the ENQUIRY character, or \u0005).
That's a good point. However, Pd's escape sequences work quite differently than in those languages, because the set of special characters is not the same. For example, Pd doesn't need to escape '
, ?
or "
. Nevertheless, I agree that repurposing \<number>
could be confusing to people coming from those languages.
What about using an unused escape sequence, like \s
, to force the following characters to be interpreted as a symbol, e.g. foo \s123
?
Generally, there's a problem with saving new escape sequences, because it means that your patch might not work as intended when opening it on older Pd versions...
As a side note: Besides Pd's "special" characters (;
, ,
, $
), we can only escape whitespace. I think \n
(newline), \r
(carriage return) and \t
(tab) could be easily added to the list, as people coming from C like languages would naturally expect this to work.
In a distant future, we might even support \uhhh
and \Uhhh
for typing Unicode symbols :-)
\s
is a good idea.
I'd recommend closing this issue and opening a new one specifically about improving escape mechanisms.
i don't know about closing: the original issue described here is that a string \5
(whether that's valid or not) doesn't get saved as such.
i'm guilty as charged for derailing this into a "\5
is not a way to turn floats into symbols" discussion (on which i think we all agree by now).
so what should we do with a string \5
?
so what should we do with a string \5?
Different programming languages/runtimes handle invalid escape sequences differently. In the case of foo \s
, Python3 would happily print foo \s
, while the C/C++ standard libraries (that I've tested) would drop the backslash and print foo s
, but they would also give a compiler warning.
Personally, I would opt for dropping the backslash in invalid escape sequences. Additionally, we could also print an error message, like "unsupported escape sequence ... in symbol ...`.
my question was more specifically geared towards \<d>
with <d>
being an integer.
but anyhow, my ~libc~ (EDIT:) C-compiler gives me:
string in the code | hex representation in the runtime | notes |
---|---|---|
\s |
73 00 |
warning: unknown escape sequence: '\s' |
\5 |
05 00 |
|
\25 |
15 00 |
025 == 0x15 == 21 |
\22.2 |
12 2E 32 00 |
022 == 0x12 == 18 |
\270 |
B8 00 |
0270 == 0xb8 == 184 |
i probably should have known that \<num>
(specifically r"\[0-9]{1,3}"
) is used for the octal representation of a character.
I like this. I think it makes sense to adopt something like C's conventions for this, when possible.
UPDATE: We are already doing this, to some degree, with the number representation, ie. %g
.
UPDATE 2: I think we are doing this already, but it would be good to hide aspects of the implementation from this, ie. TCL-specific escaping should be hidden, where possible. Best to keep GUI implementation agnostic as much as we can IMO.
where is this going? can I close this?
I found out you can escape a float with backslashes and you can create a symbol like that
the problem is that the backslash disappears from the message box when the patch is reopened