Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: A "but" operator.

by theorbtwo (Prior)
on Sep 27, 2004 at 18:09 UTC ( [id://394275]=note: print w/replies, xml ) Need Help??


in reply to A "but" operator.

It's quite simple, really. "but" is just like "and" when used as a conjunction. In natural language, "and" has the conotation that the two things are normally in agreement, or neutral toward each-other, whereas "but" has the conotation that the two things are normally in oppisition. Note that people very rarely make "but" lists, but quite often make "and" or "or" lists; "but" is a preposition only, but "and" and "or" are list specifiers.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: A "but" operator.
by muba (Priest) on Sep 27, 2004 at 18:21 UTC
    Maybe I don't get you right, maybe you're wrong. I'm not sure. The way I get it, you say "but" is just like "and". How's that possible? I could say: "you have got brown hair AND I have got black hair" (this indicates both of them are true). I could say: "you have got brown hair OR I have got black hair" (one of them would be true, but it is not specified which one [update that would be XOR. At least one of them is true, in a programmer's view]). I could also say: (oh, I think I do understand you now) "you have got brown hare BUT I have got black hair" (again, both would be true). Ok.

    Hmm, nice stuff to think about :)




    "2b"||!"2b";$$_="the question"
    Besides that, my code is untested unless stated otherwise.
    One more: please review the article about regular expressions (do's and don'ts) I'm working on.
      you say "but" is just like "and". How's that possible?

      In fact, some languages have words that can be translated into English as either "but" or "and". For example, the Greek postpositive "de" (delta epsilon) is most frequently translated into English as "but", but it can also be translated into English as "and" (though for "and" the conjunction "kai" is much more common).</philolophile>

      The meaning of "but" and "and" in English _is_ different, but the difference doesn't have very much to do with the meaning of "and" in Perl. The real difference is that "but" implies that the second item may be surprising given the first, while "and" has only the more basic meaning of conjunction. Still, in terms of their value as boolean operators, both would mean the same thing: the first argument is true; the second argument is also true. Boolean logic doesn't much care about surprise value. Think about the difference in meaning between "The ball is blue and it is also heavy" versus "The ball is blue but it is also heavy". In both cases we're dealing with a heavy blue ball, but in the latter case there is an implication (quite a surreal one, given the usual presumption that color and weight are pretty much orthogonal) that we might ordinarily expect a blue ball not to be heavy -- but this one is.

      And, as pointed out, the word "but" is going to be used in Perl6 for something really cool that will be sure not to disappoint you, though not as a boolean operator:

      my $x = ("The answer to the ultimate question of life, the universe +, and everything" but 42 but false but undef); print "Number: " . (0+$x) . "\n"; print "String: " . $x . "\n"; print "Boolean: false\n" unless $x; print "Undefined" if not defined $x;

      (I might have some legacy Perl5 syntax in there by mistake. For some reason, though I want to learn and use Perl6, I keep finding myself being lured away by Perl5 and its persistent siren call of actually being ready for use now.)


      "In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

        I didn't acutally /quite/ say that "but" == "and" in English. I said that they have the same "denotations", but different "connotations". A word's denotation is it's plain meaning -- what it says on it's face. Quite literaly, what it denotes. That's the meaning that programming languages can hope to capture. That's the meaning of words that scientific discourse and legalisims should revolve about. It's simple, clear, and to the point. "connotations" are the more elusive meanings of worlds. They're what makes poetry and prose interesting. They're shades of meaning, hints at something beyond the mear denotations. They're why two words that are synonyms can give much different effects when said. They're what makes translation really difficult.

        Another concrete example... saying to a woman that "danm, your tits are hot" fits in a different conversation then saying to her "I find your breasts highly attractive". (I say, not being a woman, and being the sort to use the first phrase.) The words have the same denotations. They have very different connotations.

        If you interchange "but" and "and" in a sentance, the sentance still has the same meaning, but different implies something different.


        Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

        If I get that right... it is possible to give one variable multiple values, including undef?
        That's cool indeed! But ("but" :) )... how can a variable have a (or more) value(s) and still be undefined?




        "2b"||!"2b";$$_="the question"
        Besides that, my code is untested unless stated otherwise.
        One more: please review the article about regular expressions (do's and don'ts) I'm working on.
        And in Greek you have 'kai de kai', literally 'and but and', but usually translated as 'and moreover'.

        'But' can also be used to erase the compliment that went before it, as in "the car is fast, but unreliable." These descriptions can be made less harsh by changing the word 'but' to 'and'.

        It should work perfectly the first time! - toma
      "A but B" <=> "A and !B". Which, scarily enough, is equivalent to "!(A -> B)" (A implies B, or "if A, then B"). Which, if you think and squint, makes a weird kind of sense.

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

        I think you are trying to say a "but" operator is equivalent "not and" operator and that !(A->B) is equivalent to "but". I am assuming that "!" symbolizes the negation operator and "->" symbolized the if-then ( or implies ) operator.

        Yet ...
        PQP->Q
        TTT
        TFF
        FTT
        FFT

        PQP and Q!(P and Q)
        TTTF
        TFFT
        FTFT
        FFFT
        So I would say "A and !B"is not equivalent to "!(A -> B)" and I wouldn't say "A but B" <=> "A and !B", but I could just be misunderstanding your notation. :)

        As far a what a but operator is I would say it should be equivalent to the "Boolean And" operator. And is not needed in a programming language. The word "but" is used in commonly to emphasis that an assumption is false. Example ...

        If a student where to errorously assume that multiplaction is 
        the same as addition the student might state ...
        
        
        1 + 1 = 2 and 2 + 2 = 4 and 2 * 2 = 4 and 1 * 1 = 2
        
        
        ... which we know to be false.  The student's teacher would say ...
        
        
        1 + 1 = 2 and 2 + 2 = 4 and 2 * 2 = 4 but 1 * 1 != 2
        
        
        ... to correct the student.
        
        
        This is the same as
        
        
        1 + 1 = 2 and 2 + 2 = 4 and 2 * 2 = 4 and 1 * 1 != 2
        
        
            T and T and T and T is TRUE
        
        
        It is not equal to
        
        
        1 + 1 = 2 and 2 + 2 = 4 and 2 * 2 = 4 and not (1 * 1 != 2)
        
        
        
             T and T and T and F is FALSE
        

        But merely gives emphasis to the fact that the student's assumption is false.

        Janitored by davido: removed excess spaces within pre tags that caused horizontal scrolling.


        Plankton: 1% Evil, 99% Hot Gas.

        Since "A but B" is really a conjunctive inversion, discursively it should be equivalent to "A and not B".

        And since "A and not B" is equivalent to "not (if A then B)", or in other words, "not (B if A)", couldn't this be said thusly, to be perly, "B unless A"?

        Thoughts?
        -v
        "Perl. There is no substitute."
      In your analogy, but can't be XOR, it's ($A and !$B). XOR is ($A and !$B) || (!$A and $B). Or equivalently, but could be "A and (A XOR B)", if you prefer to keep it complicated and silly, in a Lewis Caroll (sp?) sort of way.
Re^2: A "but" operator.
by Theo (Priest) on Sep 27, 2004 at 23:32 UTC
    The English "but" is a little hard for me to pin down in my mind. Perhaps it has too many meanings to make a good programming word.
  • I had brown hair, but now it's gray. (both are true)
  • He wanted to go, but had other commitments. (condition modified by 'but phrase')
  • She had but one laptop. (some kind of exclusive emphasis?)
  • -Theo-
    (so many nodes and so little time ... )

      The first meaning could actually be useful in programming to indicate that a variable should have a different value under certain conditions, but with the ability to remember the past condition and revert to it automatically.

      Then you could do something like this:

      my $var1 = "foo" but ($some_input_var eq 'show_bar') { "bar" }; print $var1; # prints 'foo' #$some_input_var is changed by a user to 'show_bar'; print $var1; #prints 'bar' #$some_input_var is changed to something else print $var1; #prints 'foo'

      Of course after thinking about it, its totally pointless ... one could do the same thing with

      $var1 = sub { 'foo' ? $some_input_var ne 'show_bar' : 'bar' };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394275]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-19 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found