logoalt Hacker News

everforwardtoday at 4:15 PM1 replyview on HN

That makes a lot of sense to me. The implementation feels odd to me, though. If I’m reading it right, I type in literals normally and then all these hooks decide whether they want to change what I’ve typed in? It feels like I have to remember the custom literals I have installed to make sure I don’t accidentally conform to some spec and end up with a custom literal instead of the string I wanted.

Something like EDN readers seem saner to me where I wrap the value in something that denotes the function to use to parse the value. If I do “192.168.1.0/24” I get a string literal, if I do #cidr{192.168.1.0/24} then it hands the value off to the cidr custom literal.

That’s my 2 cents, I hate when things implicitly modify my literals.


Replies

tertstoday at 6:30 PM

That's kind of right, but they are adding new literals, not changing existing ones. The hooks are for the lexer and they can decide what syntax they accept. The syntax it defines would be a parse error if the hook is not used. But, indeed, this can be misused by accepting too much though, for instance when an IP addr also accepts a float. So the hook needs to be a bit careful.

The `#cidr{...}` syntax would work but then it wouldn't be much more convenient than just constructing the value with normal functions, I think.