
On Sat, Feb 24, 2024, at 6:22 AM, Information via ruby-talk wrote:
So why should be there another result if using and/or instead of &&/||?
https://www.prestonlee.com/2010/08/04/ruby-on-the-perl-origins-of-and-versus...
(1 and 2 or 3 and 4) != (1 && 2 || 3 && 4) - That shouldn't be the case!
Perhaps not. I don't know why matz gave the "and"/"or" keywords the same precedence rather than making "and" higher precedence than "or", but that's been the case in ruby forever. Perhaps it was a mistake since perl does maintain the relative precedence: $ perl -e 'print(1 && 2 || 3 && 4);' 2 $ perl -e 'print(1 and 2 or 3 and 4);' 2 Or, perhaps matz felt that since the keyword form is intended for flow-control, the flat precedence was appropriate. $ git log -p parse.y [...] commit 3db12e8b236ac8f88db8eb4690d10e4a3b8dbcd4 (tag: v1_0_r2) Author: matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Fri Jan 16 12:13:05 1998 +0000 Initial revision git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/parse.y b/parse.y new file mode 100644 index 0000000000..02ff720bb3 --- /dev/null +++ b/parse.y @@ -0,0 +1,3717 @@ +/************************************************ + + parse.y - + + $Author$ + $Date$ + created at: Fri May 28 18:02:42 JST 1993 + + Copyright (C) 1993-1996 Yukihiro Matsumoto + +************************************************/ [...] +%left OR AND [...] +%left OROP +%left ANDOP [...]