5 ms·
Well, this is a nice coincidence, Nim also added support for rightward assignments today! https://play.nim-lang.org/#ix=2x7r https://play.nim-lang.org/#ix=2x7r
by zevv 6y ago
Well, this is a nice coincidence, Nim also added support for rightward assignments today!
https://play.nim-lang.org/#ix=2x7r https://play.nim-lang.org/#ix=2x7r
- moonchild 6y agoFunny you should mention it, raku just got the same feature! https://tio.run/##K0gtyjH7/7@4NEkhMy8ts8Lq0Gpbu0O7NVQSdRRUgGLFCkXlmgrVILatgkqiQi0XV26lgmdeCZCTnmrNxWVipGBrB@MUJ1ZCmP//AwA https://tio.run/##K0gtyjH7/7@4NEkhMy8ts8Lq0Gpbu0O7NVQSdRRUgG...
- kbenson 6y agoDoesn't Raku essentially already have this with feed operator? [1] 1: https://raku.guide/#_feed_operator https://raku.guide/#_feed_operator
- moonchild 6y agoNot quite. For example: > my $x (Any) > 1 ==> $x (1) > 2 ==> $x (2) > 3 ==> $x (3) > $x [1 2 3] If ==> were simply assignment, we would expect x's value to be 3.
- raiph 6y agoThere's no need for a new operator. The R metaoperator respects precedence, associativity, etc. my Int $age; 42 R= $age; say $age;
- samatman 6y agoAlright, 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.