[Semi-OT] The ^^ operator
Did anybody notice that Larry has slipped in an anime smiley operator? Between "^^" and the recent musing about "wa"... On a closely related note, how long do you think it'll be before someone puts this on CP6AN? class n { method n() is classmethod {# Or whatever it turns out to be return new n; } multi *infix:== (Object $lhs, n $rhs) { return ?$lhs; } } Allowing you to have code like: system("rm foo.txt") == n.n or die "Can't rm foo.txt"; (I could think of a couple dozen offshoots of that class, actually, which is really rather scary. Definitely been chatting with too many anime fans...) -- Brent "Dax" Royal-Gordon <[EMAIL PROTECTED]> Perl and Parrot hacker Oceania has always been at war with Eastasia.
Synopsis 3: quick junction question
S3 says: 1|2 + 3&4; # (4|5) & (5|6) but shouldn't that equal (1 + (3&4)) | (2 + (3&4)) = (4&5) | (5&6) = (4|6) & 5 # ??? For one thing, OR's of AND's (DNF) is just nicer than AND's of OR's (CNF). For another, I read that as "1 or 2 plus 3 and 4"; it would be surprising if that were equal to "(4 or 5) and (5 or 6)", since that equals "5 and 5". I haven't run through many examples, but I think it should be a general rule than when combining conjuctions with disjuctions through any operation, the conjuction should distribute over the disjuction. I know these aren't strictly logical ops, but if I say @a = (0,0,0,0,1,0); print "yes" if @a[1|2 + 3&4]; I would be chagrined if it printed "yes". Then again, I would be chagrined to have to read that code, anyways. /s
Re: Synopsis 3: quick junction question
Sean O'Rourke wrote: S3 says: 1|2 + 3&4; # (4|5) & (5|6) but shouldn't that equal (1 + (3&4)) | (2 + (3&4)) = (4&5) | (5&6) = (4|6) & 5 # ??? No, it shouldn't. You should read: 1|2 + 3&4 as: "Is there a number that you can get by adding either 1 or 2 to *both* 3 and 4?" And there is: if you add 2 to 3 *and* 1 to 4, both ways you get 5. And there's no other combination of 1 or 2 that you can add to both 3 and 4 and get the same number both ways. So 1|2 + 3&4 has to equal 5. And only CNF semantics achieve that. Which is why CNF is what junctions use. Let's take another example (mainly because it's sometimes easier to see the necessity of CNF when talking about comparisons). Suppose we had written: 1|4 == 1&4 So we're asking if the lhs expression is simultaneously equal to 1 and 4. Which it is. The lhs can be 1, so its equal to 1. But at the same time it can also be 4, so it's equal to 4. So it's simultaneously equal to 1 and 4. So the comparison is true. And, under CNF semantics, that's what we get: 1|4 == 1&4 = ((1|4) == 1) & ((1|4) == 4)) = (1|0) & (0|1) = 1 But, under DNF semantics that would be: 1|4 == 1&4 = (1 == (1&4)) | (4 == (1&4)) = (1&0) | (0&1) = 0 Which is wrong. Which, again, is why we use CNF. Damian