Re: More about Records
Re: More about Records
- Subject: Re: More about Records
- From: "Bryan" <email@hidden>
- Date: Thu, 04 Jan 2001 14:16:46 -0500
In addition:
You can coerce the explicit extraction of the contents by asking for the
value of the contents as a specific class
--------------
set primes to {2,3,5,7,11}
repeat with aPrime in primes
if 7 is (aPrime as integer) then display dialog "Seven is too a prime!"
end repeat
or
set primes to {2,3,5,7,11}
repeat with aPrime in primes
if "7" is (aPrime as text) then display dialog "Seven is too a prime!"
end repeat
----------
>
From: email@hidden
>
To: email@hidden
>
Subject: Re: More about Records
>
Date: Thu, Jan 4, 2001, 1:07 PM
>
>
On Thu, 4 Jan 2001 11:11:57 +0100, "Serge Belleudy-d'Espinose"
>
<email@hidden> suggested,
>
>
> At 0:54 -0500 4/01/01, email@hidden wrote:
>
>
>
> >Its sometimes tricky to see when things are references, since if you ask for
>
the class of one, it gets its contents > evaluated. This is related to the
old
>
"comparison inside a 'repeat with' loop" problem.
>
> >
>
> > set primes to {2,3,5,7,11}
>
> > repeat with aPrime in primes
>
> > if 7 is aPrime then display dialog "Seven is too a prime!"
>
> > end repeat
>
> >
>
> >and you see no dialog. That's because aPrime on the fourth iteration isn't
>
7,
>
> >but "item 4 of {2,3,5,7,11}". Because "is" doesn't force the reference to
>
spit out its contents, the comparison > becomes a number compared to a
>
reference. And if the classes aren't the same, the result is always false.
>
>
>
> Thank you for making it so clear.
>
> I think you should add that it's easy to solve this problem by forcing the
>
item to coerce to its real value. With your > example
>
>
>
> if 8 is (aPrime+1) then display dialog "Seven is too a prime!"
>
>
>
> will work, as will adding a string to a reference to a string etc.
>
>
The universal way to fix this would be to simply realize that aPrime is a
>
reference, and to explicitly extract its contents.
>
>
if 7 is contents of aPrime then display dialog "Is too! Is too!"
>
>
For a further discussion of the difference between contents, references,
values,
>
and containers, see "Through the Looking Glass" for the White Knight's
>
discussion with Alice about the song "A Sitting on the Gate" (or was it
>
"Haddock's Eyes", "The Aged, Aged Man", or ...)
>
--
>
Scott Norton Phone: +1-703-299-1656
>
DTI Associates, Inc. Fax: +1-703-706-0476
>
2920 South Glebe Road Internet: email@hidden
>
Arlington, VA 22206-2768 or email@hidden
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users