in reply to Re: A "but" operator. in thread A "but" operator.
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 :)
"but" versus "and"
by jonadab (Parson) on Sep 27, 2004 at 19:38 UTC
|
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
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
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).
| [reply] [Watch: Dir/Any] |
|
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?
| [reply] [Watch: Dir/Any] [d/l] |
|
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
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
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.
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re^3: A "but" operator.
by dragonchild (Archbishop) on Sep 27, 2004 at 18:35 UTC
|
"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
| [reply] [Watch: Dir/Any] |
|
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 ...
P | Q | P and Q | !(P and Q) |
T | T | T | F |
T | F | F | T |
F | T | F | T |
F | F | F | T |
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. |
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
|
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."
| [reply] [Watch: Dir/Any] |
|
This is where predicate logic doesn't work as well as set theory. "A but B" is actually more akin to "A minus B", where A and B are both sets. Or, in Perl,
my @A = ( ... );
my @B = ( ... );
my %B = map { $_ => !!1 } @B;
# "A but B"
grep { !$B{$_} } @A;
Which is very close to the mixin concept that Perl6 will apply to the term "but".
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
| [reply] [Watch: Dir/Any] [d/l] |
Re^3: A "but" operator.
by SpanishInquisition (Pilgrim) on Sep 27, 2004 at 19:53 UTC
|
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.
| [reply] [Watch: Dir/Any] |
|
|