Re: Dynamic Records?? (or other alternatives)
Re: Dynamic Records?? (or other alternatives)
- Subject: Re: Dynamic Records?? (or other alternatives)
- From: email@hidden (Michael Sullivan)
- Date: Thu, 29 Nov 2001 13:19:06 -0500
- Organization: Business Card Express of Connecticut
Greg Back writes:
>
2) Can you create a record during the running of a script, such as
>
set wrdz to {"applescript":2 , "script":1}
>
adding a new entry for each new word the script encounters. Or are records
>
not the way to do this? Or do I need to go about the entire process a
>
different way. From what I can tell, you have to define everything in the
>
record before it is run. Am i wrong?
Unfortunately, yes. You can concatenate records adding in properties,
but any property name must be hardcoded in the script. There is a very
hackish way to do this that was discussed a while back on either this
list, or MacScript, but I don't remember it.
Another solution is to check out Arthur Knapp's AssociativeLib on
www.applemods.com. This library has functions to create and manipulate
an object (whose internal representation is two lists, one with key
names and one with values) that functions like a record but which can
have new keys added on the fly from variable values. I've now used this
a couple times.
Does anyone know if getting/setting the value of a record key is O(1) in
Applescript? If so, that would be a good reason to seek out the hackish
solution for your script, since the O(n) behavior of lists would start
to show on long pieces of text for your word count (your program would
end up O(n^2)).
Michael
--
Michael Sullivan email@hidden
Business Card Express of Connecticut Thermographers to the Trade
"You hate your job -- why didn't you say so? There's a support group
for that. It's called everybody; they meet at the bar." -Drew Carey