Re: If Statements
Re: If Statements
- Subject: Re: If Statements
- From: Axel Luttgens <email@hidden>
- Date: Sun, 14 Sep 2008 00:49:35 +0200
Le 13 sept. 08 à 20:32, Mark J. Reed a écrit :
"Seems" was an accurate indicatiom of my confidence in the statement.
It seemed to be true. I hadn't done enough experimentation to
convince myself that it was universally true, nor enough reading to
convince myself that it was intended to be so. I simply prefer not to
make bald statements when I don't have stronger evidence. But I don't
see how my statement was in any way "misleading".
Hello Mark,
Please be assured I never meant your statement was misleading per se;
and I even ended my message with a full agreement with your conclusions.
I just wanted to point that it could have been understood as being too
cautious, because of a very old and (almost) consistent behavior of
AppleScript.
That behavior is perhaps even better described in the older version of
the ASLG, the one related to version 1.3.7; on pages 213-214:
"When evaluating expressions containing operators, AppleScript checks
the
leftmost operand first. If the operand does not belong to one of the
legal classes
for the operator, AppleScript coerces it if possible. After coercing
the leftmost
operand or verifying that it belongs to a legal class, AppleScript
checks the
rightmost operand and coerces it (if necessary and possible) to be
compatible
with the leftmost operand. The exceptions to this rule are
expressions with the
Is Contained By, Equal, and Is Not Equal operators. AppleScript
checks the
rightmost operand first in expressions with the Is Contained By
operator.
AppleScript never coerces operands of the Equal and Is Not Equal
operators."
As a general rule with any language, there is no miracle: it behaves
according to rules, and those rules generally are available through
some kind of written documentation. Just try to write accurate C or
Perl code without reading the docs. ;-)
But, as an even more general rule, there are exceptions to be expected
as well. Paul just put his finger on such an (historical) exception.
Anyway, knowing about that "left-hand vs right-hand operand" rule,
hard coded into the language, may prove invaluable for a correct
interpretation of some results that otherwise could appear as somewhat
random.
Axel
On 9/13/08, Axel Luttgens <email@hidden> wrote:
Le 13 sept. 08 à 17:35, Mark J. Reed a écrit :
[...]
Not a bug. The comparison seems to be based on the type of the left
hand side of the operator.
And just to be more precise: "seems" is misleading, as AppleScript
always has coerced the right-hand operand accordingly to the type of
the left-hand operand in the case of binary operators.
For example, in the "new" ASLG, on may read about the ">" operator
(p.
184):
"Both operands must evaluate to values of the same class. If they
don't,
AppleScript attempts to coerce the right-hand operand to the class
of
the
left-hand operand."
So (10 > "5") is true, because it converts the string to a number
and
does a numeric comparison. But ("5" < 10) is false because it
converts the number to a string and does a lexicographic comparison.
Yep :-)
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden