3 ms·
Yes, you really can just tweak the parser; just (a) don't have a rule allowing comparisons to appear as children of other comparisons, and (b) add a rule that p
by colanderman 12y ago
Yes, you really can just tweak the parser; just (a) don't have a rule allowing comparisons to appear as children of other comparisons, and (b) add a rule that permits chains of comparisons. Types have zilch to do with this.
It's 100% a tweak to the parser.
- dllthomas 12y agoYou are absolutely correct that it could be implemented as 100% a tweak to the parser. Assuming filmor is correct, in practice as it happens to be implemented in the Python code base it is not 100% a tweak to the parser - changing the structure of the produced AST means tweaks down the line. I think the change to the parser is still the most meaningful piece, though, even there.
- dllthomas 12y agoInterestingly, you can do it with types and no parser help: https://gist.github.com/dlthomas/d18d475068f23584d473#file-chained-hs https://gist.github.com/dlthomas/d18d475068f23584d473#file-c... Obviously, that's not what's going on in Python... It could be smoother and more generic if Haskell permitted specifying defaulting for non-numeric types. But it does support things like: *Main> 2 < 3 < 4 < 4 :: Bool False *Main> 2 < 3 < 4 <= 4 :: Bool True *Main> 2 <= 3 < 4 <= 4 :: Bool True *Main> 2 <= 3 > 4 <= 4 :: Bool False *Main> 2 <= 6 > 4 <= 4 :: Bool True