Well, this is a nice coincidence, Nim also added support for rightward assignments today! https://play.nim-lang.org/#ix=2x7r
https://tio.run/##K0gtyjH7/7@4NEkhMy8ts8Lq0Gpbu0O7NVQSdRRUgG...
61–70 of 172 posts
Well, this is a nice coincidence, Nim also added support for rightward assignments today! https://play.nim-lang.org/#ix=2x7r
https://tio.run/##K0gtyjH7/7@4NEkhMy8ts8Lq0Gpbu0O7NVQSdRRUgG...
> While the above pattern has become standardized, it feels somewhat unnatural as we read most of the spoken languages from left to right. Is this true (the 'unnatural' part)? Reading left to right, `age = 42` can be read as "age is 42" which feels perfectly natural in English. `42 => age` would be read as "assign 42 to age"? This feels more awkward to me. I'm not sure I understand why anyone would want Rightward ass…
But “age is 42” is a statement/Boolean, not a mutation. “Let age be 42” is more natural, but doesn’t sound well on reassignments (“let age now be 42”?)
Can you mix left assignments, right assignments, and assignments in expressions all in one statement? That will be great for obfuscating code.
Why? Why does ruby have an infinite amount of ways to do the same thing?
As someone else said in these comments, Ruby offers multiple ways to express things, so you have more options to "write how you think" as opposed to being pushed to "think how the language wants you to write". I'm not saying it's good or bad, I'm just saying that appears to be one of the reasons for it.
Well, this is a nice coincidence, Nim also added support for rightward assignments today! https://play.nim-lang.org/#ix=2x7r
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?
Well, this is a nice coincidence, Nim also added support for rightward assignments today! https://play.nim-lang.org/#ix=2x7r
Funny you should mention it, raku just got the same feature! https://tio.run/##K0gtyjH7/7@4NEkhMy8ts8Lq0Gpbu0O7NVQSdRRUgG...
Earlier quoted context omitted.
A math tutor of mine was actually pretty angry at computer science for writing things like `a=1; a=2; //so 1=2 ?` I guess he'd rather have the "assign 42 to age"... Except he'd probably read `42 => age` as "42 implies age", which would probably cause him more sleepless nights ;)
He’d probably like a := 42 which is in a lot of languages actually! Also Erlang and other fp’s do consider = equivalence.
To counter some of the complaints regarding readability, a major use case for this is simply hacking stuff together in the REPL. Sometimes you notice you want to have your result as a variable when you've just typed a line, and other solutions for this problem (Ctrl+A or ENTER plus foo = _) are not universal. Disclaimer: I'm not a core dev but saw a discussion amongst them about such use cases.
This is the exact reason I've wanted this, for a long time. I even asked Matz about it a conference once, probably 10-ish years ago.
>> 4 + 2
=> 6
>> _
=> 6
>> "abc" + "def"
=> "abcdef"
>> _
=> "abcdef
Adding this kind of syntax for something that's already trivial to do is honestly kind of distressing for me as a Ruby developer who's been around since early 1.8.I still strongly believe that the `key: value` hash syntax was a massive mistake. That's a lost battle, but this is getting ridiculous.