Record quirk - or bug?
Record quirk - or bug?
- Subject: Record quirk - or bug?
- From: email@hidden
- Date: Thu, 31 May 2001 18:27:54 -0400
Message: 4
On Wed, 30 May 2001 19:31:55 -0700, Paul Berkowitz asked,
>
Can anyone explain this?
>
>
set rec to {a:1, b:2, c:3}
>
-- {a:1, b:2, c:3}
>
>
length of rec
>
-- 3
>
>
count rec
>
-- 3
>
>
contents of rec
>
-- {a:1, b:2, c:3}
>
>
length of (contents of rec)
>
-- 3
>
>
count (contents of rec)
>
-- 0
I suspect the count command is latching onto the "contents" and seeing it as the
class of items to count. If you don't specify an class, it defaults to "item",
but in this case, you are looking for a "content" class of item, and you have
none.
The most disconcerting thing is that the parentheses don't force (contents of
rec) to evaluate. The command is still the equivalent of
count every content of rec
In the language guide, you'll note that the Count command takes a reference to
an object, which means it doesn't evaluate or dereference its argument. This
behavior is necessary, because the forms like, 'count every paragraph of window
1 of document "Foo"' you want AppleScript to send a count message to the
application with a reference to the object, not to get all the paragraphs and
then count them in AppleScript.
Still, I would class this as a bug, because "contents" is not a plural of a
class name, but a property name. Other property names give similarly odd
behavior:
count length of rec
--> result: 0
count class of rec
--> 0
and similarly zero for "rest of somelist", "reverse of somelist". User
properties of records give an error message that varies with the form of the
"count" statement. "Count each a in rec" gives "current application doesn't
understand the count message", while "count every a in rec" gives a compile
error, "Expected class name but found identifier."
--
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