Re: Building records from references
Re: Building records from references
- Subject: Re: Building records from references
- From: Philip Aker <email@hidden>
- Date: Tue, 13 Jan 2009 09:25:32 -0800
On 2009-01-13, at 06:07:38, Nigel Garvey wrote: 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.
I think all of these are confirmation (AppleScript 2.0.1).
set rlst to {{a:"Fred"}, {b:"Bert"}, {c:"aardvark"}} set reco to {} as record repeat with r in rlst set reco to reco & contents of r end repeat reco
set rlst to {{a:"Fred"}, {b:"Bert"}, {c:"aardvark"}} set reco to {} as record repeat with r in rlst set reco to reco & r end repeat reco
set rlst to {{a:"Fred"}, {b:"Bert"}, {c:"aardvark"}} set reco to {} as record repeat with r in rlst log class of reco log class of r set reco to reco & (r as record) end repeat reco
Philip Aker
Democracy: Two wolves and a sheep voting on lunch.
|
_______________________________________________
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