• 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: Scott Babcock <email@hidden>
  • Date: Thu, 7 Feb 2008 11:19:43 -0800
  • Acceptlanguage: en-US
  • Thread-topic: Coercion of list to record

You missed part of the code:

on listToRecord(L)
    script myScript
        return {<class usrf>:L}
    end script
    return run script myScript -- MISSING CODE
end listToRecord

set R to listToRecord({"name", "haha", "age", 51})
--> {|name|:"haha", age:51}

Without the 'run script' line in your handler, the result of your call is a script object instead of a record.

-----Original Message-----

Date: Wed, 6 Feb 2008 13:19:31 -0700
From: "Robert R. Horning" <email@hidden>
Subject: Coercion of list to record
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

Hi,

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?

Thanks, Bob.
 _______________________________________________
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: Can't Compile Mail Rule
  • 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