Re: coerce lists to records
Re: coerce lists to records
- Subject: Re: coerce lists to records
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 17 Nov 2000 19:45:11 -0500
on 11/17/00 10:42 AM, Yosemite at email@hidden wrote:
>
-- i am sure there are better ways but this does work
>
>
set aList to {"firstname", "Robert", "lastname", "Robertson"}
>
set aRec to {}
>
repeat with i from 1 to ((number of items in aList) / 2)
>
set l to item (i * 2 - 1) of aList
>
set v to item (i * 2) of aList
>
set bRec to run script ("set bRec to {" & l & ":\"" & v & "\"}")
>
set aRec to aRec & bRec
>
end repeat
I think that is just a brilliant solution.
But it would be a little cleaner if you used the Repeat command's "by"
parameter. Then you could just use "+ 1" at the critical point, instead of
all that slow multiplication stuff.
Sort of like this (untested):
Repeat with i from 1 to length of aList by 2
set l to item i of aList
set v to item (i + 1) of aList
... And so on.
-
Bill Cheeseman, Quechee, Vermont <
mailto:email@hidden>
The AppleScript Sourcebook
<
http://www.AppleScriptSourcebook.com/>
Vermont Recipes-A Cocoa Cookbook
<
http://www.stepwise.com/Articles/VermontRecipes/>