Re: Coercion of list to record
Re: Coercion of list to record
- Subject: Re: Coercion of list to record
- From: Kurt Klamp <email@hidden>
- Date: Wed, 6 Feb 2008 22:06:43 +0100
Am 06.02.2008 um 21:23 schrieb Robert R. Horning:
Hi,
I wish to create a list of records at run-time under Tiger. Both
the name (property) and value of each record in the list will come
from an Excel workbook. The names will equal the Excel column
headers and the values will be the ranges of the columns that
include those headers. I can extract the necessary data from the
workbook, and can create a list consisting of:
{(columnHeader1: range1), (columnHeader2: range2), ...},
where columnHeaders and ranges are variables containing the
retrieved data. But so far I've been unable to coerce the list of
variables containing strings into a list of records.
set R to listToRecord({"name", "haha", "age", 51})
log |name| of R --Expect to get (*haha*), get (*name*). (Note
'pipe' symbols enclosing name in log statement.)
log age of R --Expect to get (*51*), get (*age*)
log nonsense of R --Expect to get error message, get (*nonsense*)
Has anyone a technique that will coerce a list of variables
containing strings into a list of records?
have a try with this.
on listToRecord(l)
set ret to {}
repeat with i from 1 to (count l) div 2
set end of ret to item i of l & ":\"" & item (i + 1) of l & "\""
end repeat
set {otid, AppleScript's text item delimiters} to {AppleScript's
text item delimiters, ","}
set ret to ("{" & ret as string) & "}"
set AppleScript's text item delimiters to otid
return do script ret
end listToRecord
set r to listToRecord({"name", "haha", "age", 51})
--> {name:"haha", haha:"age"}
hth
-- Kurt
_______________________________________________
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