Re: My Worrisome Lists :-)
Re: My Worrisome Lists :-)
- Subject: Re: My Worrisome Lists :-)
- From: has <email@hidden>
- Date: Mon, 4 Feb 2002 14:25:58 +0000
Stephen Swift wrote:
>
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 you want are hash (aka associative) arrays. Many languages have them
built in; AppleScript unfortunately does not. Chris N has already said
they're on the To Do list for some future version of AS, though when it'll
happen is anyone's guess. :(
Meantime, there are several 3rd-party options available to you...
--
To access records as if they were hashes:
RecordAccess (see www.osaxen.com) - osax; fast, not sure if it's OS X-savvy
hashLib (see Script Builders on macscripter.com) - one of mine; requires
Smile (fairly fast), though can be converted to Standard Additions (dog
slow) if necessary
The <<usrf>> method developed by Olof Hellman and others - not sure if
there's a definitive, ready-to-use package available for this, though I'm
sure folk will be happy to post the code for you.
--
To use your own "associative array" objects:
Arthur J Knapp has written two different solutions to this one:
- AssociativeArrayLib (see www.applemods.com [note: it may still be down;
I'm sure Arthur could help though])
- a tid-based version that he's posted to this list (note: the original
code had a bug; make sure you get a bug-fixed version)
The first is slower, though case-insensitive; the second is fast, though
case-sensitive and only works with strings.
I've also written my own version which basically nicked all the best ideas
from Arthur and put them together (fast, tid-based; values can be any
class, not just strings; case sensitivity in keys is optional). It's
[still] not been publically released, but you could probably twist my arm
if you really wanted to.
--
I must confess that I've kind of moved away from the record-as-hash
approach to using custom objects; the big advantage is that they're not
dependent on 3rd-party apps or osaxen, so are very portable. Plus, it's
pretty easy to customise them if you need extra features (they're plain AS,
and tend to be OO designs, so modifying/expanding them is a snap). It's
mostly down to what your requirements and/or personal preferences are.
>
If anyone would like to administer a dope slap and show me the solution I'm
>
obviously overlooking, please, please do so. :-)
Not at all. It's one of the biggest butt pains out that there's no simple
or obvious way of doing this stuff. HTH.
Cheers,
has