3 ms·
> Which makes sense, it's got the smallest language spec of any of them I think go is fairly small, too, but “size of spec” is not always a good measure for th
by Someone 11mo ago
> Which makes sense, it's got the smallest language spec of any of them
I think go is fairly small, too, but “size of spec” is not always a good measure for that. Some specs are very tight, others fairly loose, and tightness makes specs larger (example: Swift’s language reference doesn’t even claim to define the full language. https://docs.swift.org/swift-book/documentation/the-swift-programming-language/aboutthelanguagereference/ https://docs.swift.org/swift-book/documentation/the-swift-pr...: “The grammar described here is intended to help you understand the language in more detail, rather than to allow you to directly implement a parser or compiler.”)
(Also, browsing golang’s spec, I think I spotted an error in https://go.dev/ref/spec#Integer_literals https://go.dev/ref/spec#Integer_literals. The grammar says:
decimal_lit = "0" | ( "1" … "9" ) [ [ "_" ] decimal_digits ] .
Given that, how can 0600 and 0_600 be valid integer literals in the examples?)
- neild 11mo ago0600 and 0_600 are octal literals: octal_lit = "0" [ "o" | "O" ] [ "_" ] octal_digits .
- j-scott 11mo agoNever mind, I was wrong. Here’s a playground showing how go parses each one: https://go.dev/play/p/hyWPkL_9C5W https://go.dev/play/p/hyWPkL_9C5W
- mseepgood 11mo ago> Octals must start with zero and then o/O literals. No, the o/O is optional (hence in square brackets), only the leading zero is required. All of these are valid octal literals in Go: 0600 (zero six zero zero) 0_600 (zero underscore six zero zero) 0o600 (zero lower-case-letter-o six zero zero) 0O600 (zero upper-case-letter-o six zero zero)
- j-scott 11mo agoMy bad! I was wrong; added a playground demonstration the parsing behavior above.
- j-scott 11mo agoMy original comment was incorrect. These are being parsed as octals, not decimals: https://go.dev/play/p/hyWPkL_9C5W https://go.dev/play/p/hyWPkL_9C5W
- mseepgood 11mo agoYou're looking at the wrong production. They are octal literals: octal_lit = "0" [ "o" | "O" ] [ "_" ] octal_digits .
- Someone 11mo agoThanks! Never considered that a 21st century language designed for “power of two bits per word” hardware would keep that feature from the 1970s, so I never looked at that production. Are there other modern languages that still have that?