| 11 Dec 2025 |
Charles | so a-1 would parse as identifer a minus literal 1, not an identifier a-1 | 21:14:18 |
Rutile (Commentator2.0) feel free to ping | In reply to @charles:computer.surgery
if i were designing a language from scratch and i wanted support for more or less arbitrary identifiers, i would have two kinds of identifiers:
- literal identifiers, like
foo, foo_bar, _foo123, etc; XID_Start followed by >=0 XID_Continue
- string identifiers, like
i"..." to use an arbitrary string of characters and escape sequences to construct an identifier
This honestly sounds quire reasonable | 21:14:27 |
Charles | if you want a-1 as an identifier you'd write i"a-1" instead | 21:14:32 |
Charles | this way you get the convenience of literal identifiers for the common cases, - behaves in an obvious way, and i"..." is an "escape hatch" for other cases like i"1Password" or whatever | 21:16:19 |
helle (just a stray cat girl) | so in addition to the formal form, I would always ask, "okay, so you are now teaching someone who just finished introduction to programming and introduction to Java, how would you explain this" | 21:17:26 |
Charles | also i would probably want to define e.g. a and i"a" as syntactically equivalent | 21:17:39 |
Charles | "if you want arbitrary characters in your identifier then you can wrap it in i"..."" | 21:18:12 |
helle (just a stray cat girl) | yeah, and when does it become "arbitrary"? | 21:18:26 |
Charles | immediately | 21:18:43 |
helle (just a stray cat girl) | (because while most of the people discussing this here are aware of how to read documentation like this, it really needs to teachable to people who are not this deeply involved) | 21:18:45 |
helle (just a stray cat girl) | also why the "i" choice (I mean I have some pros and cons to it, but one of the downsides is fonts not always being super clear with it) | 21:19:30 |
Charles | alternatively you can replace "arbitrary characters" with "characters that aren't normally allowed in identifiers" | 21:19:38 |
helle (just a stray cat girl) | welcome to me having some UX and teaching background :3 sorry about that | 21:19:55 |
Charles | i for identifier but i don't care, feel free to pick something else like v for variable | 21:20:08 |
Rutile (Commentator2.0) feel free to ping | non-arbitrary = [a-zA-Z][\w-]*(?<=-) | 21:20:09 |
helle (just a stray cat girl) | s"" may actually work very welll, for string literal | 21:20:38 |
Rutile (Commentator2.0) feel free to ping | also, what exactly is the difference between a variable and an identifier, especilaly in the context of nix? | 21:20:39 |
helle (just a stray cat girl) | or idk | 21:20:43 |
helle (just a stray cat girl) | but I am just using this to demonstrate cases to worry about with UX and teaching, not so much as an actual thing to work on right now | 21:21:08 |
Charles | my point is that i don't think this is complicated to explain, it's maybe one to three sentences depending on how specific you really want to be i guess | 21:21:17 |
Rutile (Commentator2.0) feel free to ping | * non-arbitrary = [a-zA-Z][\w-]*(?!<=-) | 21:21:21 |
helle (just a stray cat girl) | I agree, but already having to think about that helps shape further choices | 21:21:50 |
Charles | it's not like i wasn't thinking about explainability when i came up with this idea | 21:22:14 |
helle (just a stray cat girl) | like, I've seen some amazing programming concepts that people should learn early on, and omfg when I had to try and teach them to people | 21:22:29 |
Charles | in the context of nix i don't think there really is a difference | 21:22:59 |
Charles | in other languages though function names, class/struct/enum/type names, variable names, etc are all identifiers | 21:23:19 |
helle (just a stray cat girl) | and this can go as simple as "well, Python has like at least 3 string formatting mini languages, of which 2 are relevant to this day" | 21:23:22 |
Rutile (Commentator2.0) feel free to ping | I'd just explain it as "has to be a letter at first, then any amount of word characters (letter or digit) and might include a hyphen; everything else requires wrapping in an ident string.
| 21:23:29 |
helle (just a stray cat girl) | like that one gave us no end of headaches | 21:23:32 |
Charles | variable names are a subset of identifiers | 21:23:53 |