Re: Efficiently using whose on Address Book users
Re: Efficiently using whose on Address Book users
- Subject: Re: Efficiently using whose on Address Book users
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 22 Feb 2004 19:38:53 -0800
On 2/22/04 7:02 PM, "Michelle Steiner" <email@hidden> wrote:
>
On Feb 22, 2004, at 6:38 PM, Paul Berkowitz wrote:
>
>
> set foundPerson to (first person where value of every email of it
>
> contains "email@hidden")
>
>
I think this reads a bit better to humans; it makes no difference to
>
the computer:
>
>
set foundPerson to (first person whose emails's value contains
>
"email@hidden")
I guess it's a personal preference. The AppleScript
singular-property-of-plural-elements doesn't really have any exact
correspondence in English, but
property of every element of something
"sounds" more English to me than
something's elements's property
I mean: who uses "elements's" in real life? I could accept:
property of something's elements
In none of the cases would you actually expect a plural list in English.
However, this is one of the greatest features of AppleScript, so I don't
really care too much what you call it. ;-)
The other greatest feature is 'whose' clauses. I probably would normally
have written:
set foundPerson to (first person whose value of every email contains
"email@hidden")
but because there's actually a forced error in this expression (which works)
I wanted to squeeze in an 'its' to make sure it didn't get bounced.
As we discussed a week or so ago, 'contains' properly requires the same
class on either side of it (see the ASLG), even though it's happy to convert
a string to a single-item list as needed:
{"a', "b", "c"} contains "b"
--> true
is accepted because Apple Script coerces it to
{"a', "b", "c"} contains {"b"}
However, that "correct" method with lists on both sides often doesn't work
with 'whose' clauses. You get an error in AB if you try:
set foundPerson to (first person whose value of every email contains
{"email@hidden"})
That's really how it should work, but it errors. You _have_ to take
advantage of the string-to-single-list coercion:
set foundPerson to (first person whose value of every email contains
"email@hidden")
I was just "playing safe" using 'where ... its' instead of 'whose'. Not
actually needed here.
It gets trickier when the thing being contained is not a string, but
fortunately that seems to work too whenever I try it. It looks to me as if
the inventor of 'whose' clauses actually got carried away by good English
and forgot the ASLG, or maybe it's implemented on an app-by-app basis.
Whatever, I'm glad the coercion exists.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.