Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

"but" versus "and"

by jonadab (Parson)
on Sep 27, 2004 at 19:38 UTC ( #394312=note: print w/ replies, xml ) Need Help??


in reply to Re^2: A "but" operator.
in thread A "but" operator.

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


Comment on "but" versus "and"
Select or Download Code
Re: "but" versus "and"
by muba (Priest) on Sep 27, 2004 at 19:44 UTC
    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.
      how can a variable have a (or more) value(s) and still be undefined?

      You wouldn't normally want the variable to be undef, if it has meaningful values. But what if its value is an error code? Say, you want to return undef (so that the calling code knows it is getting an error, not a real value), but you want to return different _kinds_ of undef -- for example, if the error message is due to a builtin failing maybe you want to return ($! but undef), so that the calling code can try (if it wants to bother) to figure out what went wrong. One of the Apocalypse articles talks about unthrown protoexceptions -- that is, returning a value that is undef (to signal failure) but also knows how to complain in a meaningful way if it is thrown as an exception.

      However, the string/number duality is easier to see the benefit of for normal code. For example, my $postoffice = ("Galion" but 44833); Of course, you won't _have_ to do things this way. You can always go with more standard data structures, such as my $postoffice = +{ name => "Galion", zip => 44833 }; however, that requires the calling code to understand your data structure. In some cases, especially for modules, it might be better to return an object that knows how to behave different ways depending on how the calling code chooses to treat it. In other words, an object that understands and can respond to context. 0 but true is probably the most obviously useful example. We have people doing "0 but true" in Perl5 already, when returning false is wrong but 0 is the correct number. This is a symptom of the fact that the rich set of different kinds of context in Perl really makes it necessary for objects to be able to evaluate differently in different contexts.


      "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

      it is possible to give one variable multiple values, including undef?

      Yes. In fact, it's already done that way in Perl5, though you can't access the data directly from pure Perl (I believe there are XS modules that can do it).

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: "but" versus "and"
by theorbtwo (Prior) on Sep 27, 2004 at 23:54 UTC

    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).

Re: "but" versus "and"
by toma (Vicar) on Oct 01, 2004 at 06:03 UTC
    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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-08-21 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (138 votes), past polls