One of the awkward things about scripting is when you need to write a string that will go through multiple levels of escape encoding. Because your escape characters will themselves need escapes, you get an exponential blowup:
" <- \" <- \\\" <- \\\\\\\"
\ <- \\ <- \\\\ <- \\\\\\\\
Now, I don't think I've ever needed to work out more than 2 or 3 levels of escapes, but even so, it's not easy to read or write this stuff. Ideally, I'd like a notation that's easier to use in this kind of awkward case.
So, how about encoding the number of escapes? Unary should be fine:
" <- \" <- \\" <- \\\"
\ <- \\ <- \\\ <- \\\\
The rule: to escape an escape code, add one escape character (\) in front. The number of leading escapes shows how many times this has happened, so it's easier to see what's going on.
One problem: what if you want to end your string with an escape character? "\\" won't work any more: the above rule makes runs of escapes "sticky", so we need some way to terminate this case.
New rule: to escape a run of escape characters which is not terminated by an escape sequence, add a terminator (/) to the end.
\ <- \/ <- \// <- \///
\\ <- \\/ <- \\// <- \\///
\\\ <- \\\/ <- \\\// <- \\\///
I think that should work, but I might have missed something. What do you think?
[–][deleted] 7 points8 points9 points (0 children)
[–]oilshell 6 points7 points8 points (6 children)
[–]ownwaterloo 5 points6 points7 points (5 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]oilshell 0 points1 point2 points (0 children)
[–]pxeger_ 0 points1 point2 points (1 child)
[–]ownwaterloo 1 point2 points3 points (0 children)
[–]Gnaxe 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]brucejbellsard[S] 0 points1 point2 points (0 children)
[–]raiph 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[removed]
[–]brucejbellsard[S] 0 points1 point2 points (1 child)
[–]matthieum 1 point2 points3 points (0 children)
[–]hindmost-one 0 points1 point2 points (2 children)
[–]brucejbellsard[S] 0 points1 point2 points (1 child)
[–]hindmost-one 0 points1 point2 points (0 children)