Building records from references
Building records from references
- Subject: Building records from references
- From: "Nigel Garvey" <email@hidden>
- Date: Tue, 13 Jan 2009 14:07:38 +0000
Here's a rare but interesting consequence of a reference not being the
same as the referenced item. I don't know if it still applies with
AppleScript 2.0, but it goes back at least as far as AS 1.8.3.
It's possible to build a record by concatenation, like so:
set recordList to {{a:"Fred"}, {b:"Bert"}, {c:"aardvark"}}
set newRecord to {}
repeat with i from 1 to (count recordList)
set newRecord to newRecord & item i of recordList
end repeat
newRecord --> {a:"Fred", b:"Bert", c:"aardvark"}
But if, starting with {}, the concatenated values are _references_ to
records, the result is a list:
set recordList to {{a:"Fred"}, {b:"Bert"}, {c:"aardvark"}}
set newRecord to {}
repeat with thisRecord in recordList
set newRecord to newRecord & thisRecord
end repeat
newRecord --> {"Fred", "Bert", "aardvark"}
The ambiguous initial {} is apparently only interpreted as a record if an
actual record is concatenated to it. A reference to a record doesn't
count, so {} is interpreted as a list. The process then becomes a list
concatenation and the referenced records are coerced accordingly.
NG
_______________________________________________
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