3 ms·
Alright, I did in fact chuckle, out loud. But I gotta ask: does it have the correct precedence? And sure, throwing some superficial math at the problem works.
by samatman 6y ago
Alright, I did in fact chuckle, out loud.
But I gotta ask: does it have the correct precedence?
And sure, throwing some superficial math at the problem works. But is that a coincidence?
I guess what I'm asking is: how does Nim know that `=>` is infix? How does it derive the correct precedence? It looks like spooky magic, but Nim is pretty well-designed in my experience: what's going on here?
- moonchild 6y ago> how does Nim know that `=>` is infix? I expect it's the ` Haskell works the same way.
- samatman 6y agoAh, and templates are a rewrite engine on the AST! That completely slipped my mind. So the compiler itself just sees the `a = b`, the `b => a` is never visible, therefore precedence isn't germane to the template itself. Neat.
- moonchild 6y ago> So the compiler itself just sees the `a = b`, the `b => a` is never visible, therefore precedence isn't germane to the template itself. Not quite. Imagine you have: 3 + b => a Is that 3 + a = b, or a = 3 + b? Precedence still comes into it. (I don't know nim's solution.)
- samatman 6y agoHmm no I'm pretty sure in a template it's, ok I'm going to use different variable names for clarity: 3 + c => d the left hand side (3 + c) is b, and the right hand side is (d) is a, and this will apply no matter what you put on those sides, so it's rewritten in its entirety before the actual compiler sees the code. Unless you're talking about a scope violation/dirty macro situation? And yeah I don't know Nim's story around hygiene either, but: it's usually only a problem with Lisp macros, exactly because of the homoiconicity. I'd wager Nim templates have their own scope that won't shadow the rewrite.