Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octal escapes in string and character literals? #65

Open
avodonosov opened this issue May 3, 2020 · 1 comment
Open

Octal escapes in string and character literals? #65

avodonosov opened this issue May 3, 2020 · 1 comment

Comments

@avodonosov
Copy link

#59 and #60 implement unicode escapes in character and string literals.

How about octal escapes?

I discovered that both clojure language reader and the edn reader from the official clojure github project - https://github.com/clojure/tools.reader - support this.

(Octal escapes in string literals come from Java, only that Java syntax for that is backlash followed by up to 3 digits, while in Clojure and in tools.reader exactly 3 digits are required.).

In string literals the syntax is baclash followed by 3 digits: \NNN. The first digit can be between 0 and 3, the last two digits are between 0 and 7.

For character literals the syntax is \oNNN. Again, the first digit is between 0 and 3, the last two are between 0 and 7.

$ clj -r
Clojure 1.10.1
user=> "aaa\062aaa"
"aaa2aaa"
user=> \o062
\2
user=> (require '[clojure.tools.reader.edn :as edn])
nil
user=> (edn/read-string "\"aaa\\062aaa\"")
"aaa2aaa"
user=> (edn/read-string "\\o062")
\2

The poposal in edn-format/edn#65 also includes octal escapes.

Not to say I personally need to use octal literals in my code. Just FYI. It may be good to have some consistency between EDN implementations.

@bpsm
Copy link
Owner

bpsm commented May 3, 2020

I'm sceptical about adding octal literals unless there's an actual need.
I consider them an ugly relic of a bygone era when some machines had word lengths that were multiples of 6 bits rather than 8. They are limited to just Latin-1: they can't even cover the whole (16-bit) range of a Java char.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants