4 ms·
I always thought, maybe because of C, that \0??? is an octal escape; so in my mind \012 is \x0a or 0x0a, and \010 is 0x08. So I find this quite confusing; mayb
by tzot 2y ago
I always thought, maybe because of C, that \0??? is an octal escape; so in my mind \012 is \x0a or 0x0a, and \010 is 0x08.
So I find this quite confusing; maybe OCaml does not have octal escapes but decimal ones, and \09 is the Tab character. I haven't checked.
- dpassens 2y agoIt is indeed a decimal escape: https://ocaml.org/manual/5.2/lex.html#char-literal https://ocaml.org/manual/5.2/lex.html#char-literal
- fanf2 2y agoYeah backslash-decimal character escapes are really rare, the only string syntaxes I know of that have them are in O’Caml, Lua, and DNS
- binary132 2y agoIs O’Caml an Irish fork of OCaml? :)
- fanf2 2y agoIt was the spelling when I first learned the language, eg https://arxiv.org/pdf/2006.05862 https://arxiv.org/pdf/2006.05862 https://caml.inria.fr/pub/old_caml_site/FAQ/stephan.html https://caml.inria.fr/pub/old_caml_site/FAQ/stephan.html
- binary132 2y agoOh, interesting. Thanks for sharing
- syncsynchalt 2y agoThere's some truth in that direction, but it's not related to backslash escapes (which are symbolic/mnemonic, \n is "[Ne]wline", \r is "carriage [R]eturn", \t is "[T]ab", and so on). Instead, consider the convention of control characters, such as ^C (interrupt), ^G (bell), or ^M (carriage return). Those are characters in the C0 control set, where ^C is \0x3, ^G is \0x7, or ^M is \0xD. You're seeing a bit of cleverness that goes back to pre-Unix days: to represent the invisible C0 characters in ASCII, a terminal prepends the "^" character and prints the character AND-0x40, shifting it into a visible range. You may want to pull up an ASCII table such as https://www.asciitable.com https://www.asciitable.com to follow along. Each control character (first column) is mapped to the ^character two columns over, on that table. That's why \0 is represented with the odd choice of ^@, the escape key becomes ^[, and other hard-to-remember equivalents. These weren't choices made by Unix authors, they're artifacts of ASCII numbering.
- sudobash1 2y agoMinor nitpick: the terminal prints the character OR'ed with 0x40 (not AND'ed).
- syncsynchalt 2y agoOop. I always make the same mistake in code too.
- wruza 2y agoBetter visible here: https://www.commfront.com/pages/ascii-chart https://www.commfront.com/pages/ascii-chart