Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I am sure the Perl internals don't optimize a lot of things, specially in examples like Abigail showed us how to reduce the number of % operations by a careful use of user shortcuts (instead of depending in Perls shortcut for logical operators)

Well, actually, if I recall well, that's exactly the truth table for XOR:

A B XOR 0 0 0 1 0 1 0 1 1 1 1 0

Ie. Either A is true and B is false, or B is true and it's A which is false. This form has the advantage over the other one than in the first part is true (ie. A and not B) there's no need to compute the second one (2 calculations, 1 per proposition). The first proposed form, which is a description of 'exclusive or' (ie. either A or B but not both at once) forces the evaluation of both parts (ie. Once proposition A and again A and proposition B to test the second one, which makes it 3. In the case it's neither A or B it shortcircuits sooner, that's right, and if A is false, then propositions A and B must be tested twice in both cases: it's a matter of taste, I guess).

And obviously I agree with you that XOR is pretty much more specialized than, say AND or PLUS...

OTOH, I'd love for Perl to implement a fast NAND (which by itself creates a complete Boolean algebra). BTW, nand doesn't make expressions easier to read, but much faster as it would shorcircuit much sooner in most cases...

Best regards,

--
our $Perl6 is Fantastic;


In reply to Re: Re: Re: Re: Anyone use "xor" in conditionals? by Excalibor
in thread Anyone use "xor" in conditionals? by bsb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-20 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found