3 ms·
I'm gonna be the one who asks the dumb question, but someone has to do it: why are expressions evaluated from right to left?
by amarcheschi 2y ago
I'm gonna be the one who asks the dumb question, but someone has to do it: why are expressions evaluated from right to left?
- bear8642 2y agoBecause that's what APL does: https://www.jsoftware.com/papers/EvalOrder.htm https://www.jsoftware.com/papers/EvalOrder.htm It also simplifies things as no need to implement BIDMAS
- abrudz 2y agoThink "normal" call syntax like foo(bar(baz(42))) and then remove the superfluous parens foo bar baz 42 The expression is evaluated from right to left. Now, let's make two of the functions into object members: A.foo(bar(B.baz(42))) Remove the parens, extracting the methods from their objects, instead feeding each object as a left argument to its former member function: A foo bar B baz 42 This is normal APL-style call syntax; right-to-left if you want.
- amarcheschi 2y agoOh now I see it, it sorts of reminds me of lambda calculus
- RyanHamilton 2y agoThanks for asking. I would guess you're asking as someone that spent years learning math notations and being taught BODMAS operator precedence. The funny thing is that if you took a 3 year old child and taught them right to left it's actually more natural than multiplication before addition. Array languages often take a fresh first principles approach rather than regurgitating common learnings. This does mean programmers from other languages can find it more confusing than total beginners.