• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Coercion of list to record
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coercion of list to record


  • Subject: Re: Coercion of list to record
  • From: Mark Alldritt <email@hidden>
  • Date: Thu, 7 Feb 2008 07:38:29 -0800

Hi,

On 7-Feb-08, at 3:53 AM, email@hidden wrote:

I wish to create a list of records at run-time.  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.

As a start, I've tried to use a technique found in Neuburg, M. (2006)
Applescript, the Definitive Guide, p253.  Here's his code:

on listToRecord(L)
	script myScript
		return {<<class usrf>> :L}		--(The << and >> are really guillemot
characters.)
	end script
end listToRecord

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?


I offer a scripting addition that provides this capability: Record & List Tools.


  http://www.latenightsw.com/freeware/RecordTools/index.html

To create records dynamically at runtime, you can do things like this:

set propNames to {"prop1", "prop2", "prop3"}
set propValues to {"Hello World", 1.2, current date}

set myRecord to set user property propNames to propValues

myRecord
--> {prop1:"Hello World", prop2:1.2, prop3:date "..."}

Cheers
-Mark

------------------------------------------------------------------
Mark Alldritt                             Late Night Software Ltd.
Phone: 250-380-1725                       333 Moss Street
Fax:   250-383-3204                       Victoria, B.C.
Web:   http://www.latenightsw.com/        CANADA  V8V-4M9

_______________________________________________
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
  • Prev by Date: Re: Coercion of list to record
  • Next by Date: Re: Coercion of list to record
  • Previous by thread: Re: Coercion of list to record
  • Next by thread: RE: Coercion of list to record
  • Index(es):
    • Date
    • Thread