XDict
XDict provides associative list type data collection. The associateve list is a collection of pairs of keys and values.
use XDict : script "XDict"
(* Make Instances *)
set empty_dict to make XDict
set a_dict to XDict's make_with_lists({"key1", "key2"}, {"value1", "value2"})
set a_dict to XDict's make_with_pairs({{"key1", "value1"}, {"key2", "value2"}})
(* obtain value *)
log a_dict's value_for_key("key1")
--result : "value1"
try
a_dict's value_for_key("key3")
on error number 900
log "No value associated with key3"
end try
(* Reverse Search *)
log a_dict's key_for_value("value2") -- result : "key2"
(* Non string values can be used as keys *)
script scriptA
end script
script scriptB
end script
a_dict's set_value(scriptA, "value3")
log a_dict's value_for_key(scriptA) --result : "value3"
try
a_dict's value_for_key(scriptB)
on error number 900
log "No value associated with scriptB"
end try
(* Iterator *)
set dict_iterator to a_dict's iterator()
repeat while dict_iterator's has_next()
set {a_key, a_value} to dict_iterator's next()
end repeat
(* Loop with a Script Object *)
script DictScanner
on do({a_key, a_value})
log a_key
log a_value
return true
end do
end script
a_dict's each(DictScanner)
script ValueExtractor
on do({a_key, a_value})
return a_value
end do
end script
set a_xlist to a_dict's map(ValueExtractor)
(* Dump the Contents for Debugging *)
log a_dict's remove_for_key(scriptA) -- result : true
a_dict's dump()
(* result :
"key1 -> value1
key2 -> value2
"
*)
History
- 1.7.2 -- 2020-01-27
- Use OpenHelpBook.scptd instead of HelpBook.osax.
- 1.7.1 -- 2017-08-07
- Fixed : "has_key" method was too slow (Thanks to Hirose-san).
- 1.7 -- 2017-04-12
- Enabled to work with AppleScript Libraries.
- Removed dependency on ModuleLoader.
- OS X 10.9 or later is required.
- Updated the help book.
- 1.6.2 -- 2015-09-04
- Internal Changes.
- 1.6.1 -- 2012-05-10
- Update Help.
- Improved layout for small windows of the Help Viewer.
- Fixed : "Edit Link" and "Clipboard Icon" links does not work in Mac OS X 10.6.
- Update Help.
- 1.6 -- 2010-02-15
- Removed dependecy on "ShowHelpBook".
- ModuleLoader 2.1 or later is required to load "XDict".
- 1.5 -- 2008-12-04
- Add set_key_comparator(), key_comparator(), set_value_comparator(), value_comparator() .
- 1.4 -- 2008-01-06
- value_for_key() will raise error number 900 instead of returning 'missing value', when there is not a value associated with a specified key.
- Because 'missing value' can be accepted as a value associated with a key.
- value_for_key() will raise error number 900 instead of returning 'missing value', when there is not a value associated with a specified key.
- 1.3 -- 2007-07-17
- First release with English documents.