Re: Rogue list?
Re: Rogue list?
- Subject: Re: Rogue list?
- From: Chris Espinosa <email@hidden>
- Date: Mon, 14 May 2001 10:15:26 -0700
On Saturday, May 12, 2001, at 07:18 AM, Paul Berkowitz wrote:
>
Could we go back to first principles here?
>
>
WHY does the Finder return an empty record rather than an empty list
>
when
>
it's asked for a direct object including a plural? I've confirmed this
>
with
>
a simple 'set theFolders to folders of myFolder':
Because it's a bug. And as a bug it's harder to find than most, because
for most purposes an empty list is equivalent to an empty record --
except in the "set end of " case and a few others (like "reverse of").
>
I purposely say 'the Finder' rather than 'AppleScript' returns an empty
>
record, even though the error message above does not refer to the
>
Finder by
>
name (as in 'Finder got an error'), because AppleScript DOES NOT error
>
with
>
plurals as direct object in some other applications:
You are correct. The Finder is returning a result, which is not an
error, and later you are using that result in a pure AppleScript
expression in an erroneous fashion, i.e. you're trying to do a list
operation on a record. So while the original bug is the Finder's (it
shouldn't be returning an empty record), the error is signalled
correctly as an error in your script, which is performing a list
operation on a record. The fact that AppleScript claims an empty record
*is* a list is another bug which makes it hard to find the two other
bugs.
>
Perhaps the reason that the class of 'theFolders' in the Finder example
>
above (and Shane's original 'theClients') is logged as list rather than
>
record is something to do with the fact that asking for 'folders', or
>
'name
>
of folders' _should_ produce a list and not a record? Is this merely
>
(yet)
>
another Finder scripting bug rather than something more basic in
>
AppleScript? Or is that too simplistic?
No, no, yes. It's logged as a list because AppleScript shares some
implementation between the list and record classes for convenience
(namely, the empty record constant is identical to the empty list
constant) but doesn't deal with differences consistently. An empty
record is considered a list except that it isn't, but an empty list is
not considered a record. It's a little complicated, it's been there
since the beginning of time, and it's relatively rare to run into it.
Chris