@egcrosser They didn't want it in the language spec as far as I can remember. It's kinda funny too because you could see people pleading for it trying to describe exactly this type of situation. They were saying something like the stack trace is too important, use loops/gotos instead.
@henriquedante Unicode is actually not a problem - Go as a language natively supports utf8 as its character encoding for the string type. For example, around 23:00-24:00, where you see "switch r = l.next() {...", r is the next rune in the output - i.e. the next unicode code point assembled through utf8 decoding. If you want to accept only upper case, just call the relevant test function from package unicode on the value of r :-)
Main objection point is that you can't write this way if you're parsing unicode patterns. For example, what would be the accept() string for accepting upper case, lower case, etc. letters ? Nevertheless, the final scanner was extremelly clean and it must have been really fun to write.
I wrote a lexer and parser API in Go, inspired by this presentation:
github.com/iNamik/lexer.go
github.com/iNamik/parser.go
DavidPFarrell 3 months ago
where's Andrew's talk on using the new template system?
argman13 6 months ago
@jimmyrcom I see. Honestly, in this particular case it's just a matter of personal preference, the for-loop is "elegant enough" too.
egcrosser 6 months ago
@egcrosser They didn't want it in the language spec as far as I can remember. It's kinda funny too because you could see people pleading for it trying to describe exactly this type of situation. They were saying something like the stack trace is too important, use loops/gotos instead.
jimmyrcom 6 months ago
@vonschlesien You're right I didn't think the test functions would be so efficient as they are
henriquedante 6 months ago
@henriquedante Unicode is actually not a problem - Go as a language natively supports utf8 as its character encoding for the string type. For example, around 23:00-24:00, where you see "switch r = l.next() {...", r is the next rune in the output - i.e. the next unicode code point assembled through utf8 decoding. If you want to accept only upper case, just call the relevant test function from package unicode on the value of r :-)
vonschlesien 6 months ago
I wonder if Go has tail call optimization. You might implement the construct described in minutes 14-15 as a tail call instead of a for-loop.
egcrosser 6 months ago
Main objection point is that you can't write this way if you're parsing unicode patterns. For example, what would be the accept() string for accepting upper case, lower case, etc. letters ? Nevertheless, the final scanner was extremelly clean and it must have been really fun to write.
henriquedante 6 months ago