Re: My Worrisome Lists :-)
Re: My Worrisome Lists :-)
- Subject: Re: My Worrisome Lists :-)
- From: email@hidden (Michael Sullivan)
- Date: Mon, 4 Feb 2002 10:49:12 -0500
- Organization: Society for the Incurably Pompous
>
It's probably come up again and again but, I'd really like to be able to
>
create records like so:
>
{"Bob":{1,2},"Jane":{3,4},"Dan":{5,6}}
>
Is AppleScript ever going to be able to use strings as records? Or is this
>
a feature of a newer AS version? I have Mac OS 8.6 (AS 1.3.7).
>
>
What I'm trying to do is a value is returned in a form of a string such
>
The_name
>
--> "Ann"
>
And I'd like to create a record "Ann" but I can't. So I've just gone with
>
creating a list.
This problem has plagued scripters for a long time. Arthur wrote
AssociativeLib as a set of handlers for dealing with matched lists of
keys and values for this very purpose.
Later in a discussion here, a couple of other folks shared a few
undocumented tricks (which may get axed in future appleshare versions,
but Chris "promised" not to do so until some sort of hashing or run-time
record key creation was implemented, because he seemed to agree that
this ability was useful and in fairly high demand.
Here's the trick. It's based on the fact that by putting a record in an
extra set of braces you can convert to a string and get the actual Apple
event data structure of the record. One can use this to either handle
things via the string itself, or by using AE struction a different way.
The most elegant (to me) solution posted was the following:
{{+class usrf;:{"hello", "goodbye"}}} as string as record
Note that "class usrf" is surrounded by guillemets which will be mangled
by the list server.
{{<<class usrf>>:{"hello", "goodbye"}}} as string as record
is what it should look like.
So you can create a handler:
on ListToRecord(a)
return {{+class usrf;:a}} as string as record
end ListToRecord
--Test client call:
ListToRecord({"hello", "goodbye", "brian", 5, "jane", 6, "leslie", {2,
3}})
-->{hello:"goodbye",Brian:5,jane:6,leslie:{2,3}}
One caveat is that keys with mixed case will be made case sensitive and
need pipes "|" around them to be accessed as records later -- so if you
don't want to deal with that, you want to make sure all the keys are
lower case before calling the handler.
Michael
--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden