Re: Getting label from a record (solution)
Re: Getting label from a record (solution)
- Subject: Re: Getting label from a record (solution)
- From: Arthur Knapp <email@hidden>
- Date: Wed, 19 Nov 2003 12:18:59 -0500
From: Christopher Nebel <email@hidden>
Subject: Re: Getting label from a record (solution)
Date: Tue, 18 Nov 2003 11:53:41 -0800
a list where the odd values are the labels (as strings) and the even
ones are the data.
In fact, the "pseudo-hash" technique created by myself and "has" is a
very good solution for mapping string-labels with values.
It's possible, of course, that any alternate technique will involve
even more code than the stuff people have been coming up with here,
but it's something to think about.
Well, yeah, there's more code, but it runs very fast, and in a script
library, you don't have to think about the code. This is a bare-bones
implementation:
script PseudoHashCLASS
property kcL : ASCII character 0
property kcR : ASCII character 1
property ksD : kcR & kcL
property nil : missing value
on GetValue(k)
set x to KeyAt(k)
if (x = 0) then return nil
return my paVal's item x
end GetValue
on SetValue(k, v)
set x to KeyAt(k)
if (x = 0) then
set my psKey to my psKey & k & ksD
set my paVal's end to v
else
set my paVal's item x to v
end if
return k --> see discussion....
end SetValue
on KeyAt(k)
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to kcL & k & kcR
set s to my psKey's text item 1
if (s's length = my psKey's length) then
set r to 0
else
set AppleScript's text item delimiters to ksD
set r to count of text items in s
end if
set AppleScript's text item delimiters to tids
return r
end KeyAt
end script
on newPseudoHash()
script PseudoHash
property parent : PseudoHashCLASS
property psKey : my ksD
property paVal : {}
end script
return PseudoHash
end newPseudoHash
set o to newPseudoHash()
o's SetValue("kai", "lai")
o's GetValue("kai") --> "lai"
-- nested
--
o's SetValue("kai database", newPseudoHash())
o's GetValue("kai database")'s SetValue("database item", 3.14159)
o's GetValue("kai database")'s GetValue("database item") --> 3,14159
{ Arthur J. Knapp;
<
mailto:email@hidden>;
Why do programmers confuse Halloween and Christmas?
Because Oct 31 == Dec 25.
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.