From: "Jürgen Strobel" Date: 2006-09-01T15:10:53+09:00 Subject: Re: and and or priority --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 31, 2006 at 03:01:26AM +0900, Rick DeNatale wrote: > On 8/30/06, J=FCrgen Strobel wrote: > >On Tue, Aug 29, 2006 at 08:55:09AM +0900, Michael W. Ryder wrote: > >I wouldn't say it is wrong the way ruby does it, but not exactly > >intuitive either. Choosing to follow english language rather than > >widespread convention *and* similiar constructs in ruby itself (&&, > >||, +, *, ...) may seem a bit ... anti POLS. >=20 > A perl programmer would be very surprised if AND, OR, && and || worked > any other way. Probably the most common perl idiom here is: >=20 > "some long complicated expression" or die That's not a complete example, as no precedence rules come into play here. and and or are pretty low-precedence operators in perl and ruby alike, which makes constructs like the above possible without parenthesises. But what I am driving at is this: irb(main):035:0> 1 + 2 * 6 =3D> 13 irb(main):036:0> 1 | 2 & 6 =3D> 3 irb(main):037:0> 1 | (2 & 6) =3D> 3 irb(main):038:0> (1 | 2) & 6 =3D> 2 Clearly, & binds stronger than |, same as * binds stronger than +. (In a boolean algebra those operations are the same respectively). irb(main):073:0> def pr(x) p x; x; end =3D> nil irb(main):076:0> (pr 1) || (pr 2) && (pr 3) 1 =3D> 1 irb(main):077:0> (pr 1) or (pr 2) and (pr 3) 1 3 =3D> 3 In the first case, && binds stronger than ||, but is short circuited away. In the second case "and" does not bind stronger than "or", which suprised me, given prior knowledge. Is it really only me? -J=FCrgen --=20 The box said it requires Windows 95 or better so I installed Linux --G4iJoqBmSsgzjUCe Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iQEVAwUBRPfO0Py64gyiEfXtAQKqzQgAgmuSapjIucsQxfnX7Qrq1uwPKrGZU+az u0CKHkqhsPntCNUIGizawZaqC4g8VCavc1zVqwIcdGJmB0uBx42hg+auxGIE9itP ZarfcskzrJPTEZRuwGrM7XOejVItN4+PGrWa0aA7ExFjaR8R1+DE06eHAjfkehDE kpswRNz4wpAiAcVonPPTApkApmXmePOXcSAkyWFqSceI9KG0C/WB8xwK85DPLv4C KHf5idD+m0Ne5G4xdZ9h7u8SitB3qskUCHDz7uLIIx0RtMDodpZ5F5FZxU9R3gbE QDwU1a8W3+hPNGInG830CSGNk4oqGNn12NolR8YFVSau+HmZ34SRzg== =Dytm -----END PGP SIGNATURE----- --G4iJoqBmSsgzjUCe--