Home >

Requirements

Download

Version 1.7.1 -- 2017-05-09

Old Versions

Dependencies

XList

XList provides a wrapper object to treat AppleScript's list as iterator, stack and queue.

XList will fill many missing features of AppleScript's list.

use XList : script "XList"

(* Iterator *)
set an_iterator to XList's make_with({"a", "b", "c"})

repeat while an_iterator's has_next()
set an_item to next() of an_iterator
log an_item
end repeat

(* Queue *)
set a_queue to make XList
a_queue's unshift("a")
a_queue's unshift("b")
log a_queue's shift() -- result : "b"
log a_queue's shift() -- result : "a"

(* Stack *)
set a_stack to make XList
a_queue's push("a")
a_queue's push("b")
log a_queue's pop() -- result : "b"
log a_queue's pop() -- result : "a"

(* Accessing list elements *)
set a_list to XList's make_with({"a", "b", "c"})
log a_list's item_counts() -- 3
log a_list's item_at(2) -- "b"
log a_list's has_item("b") --true
log a_list's has_item("d") --false
log a_list's index_of("b") -- 2
log a_list's index_of("d") -- 0
log a_list's delete_at(2) -- "b"
log (set_item of a_list for "e" at 2) -- "e"
log a_list's list_ref() -- {"a", "e"}

(* Conversion to Text *)
log a_list's as_unicode_with(", ") -- "a, e"

(* Accessing all items with a closure *)
script scriptA
on do(x, sender)
if x is "b" then
tell sender
set_item_at("d", current_index()) -- change an item of a list
end tell
end if
return true
end do
end script

an_iterator's enumerate(scriptA)
log an_iterator's all_items() -- result : {"a", "d", "c"}


script scriptB
on do(x)
return x & "a"
end do
end script

log an_iterator's map_as_list(scriptB) -- result : {"aa", "da", "ca"}

History

  • 1.7.1 -- 2017-05-09
    • Fixed links to XText in the help book.
  • 1.7 -- 2016-10-18
    • Enabled to work with AppleScript Libraries.
    • Remove dependency on ModuleLoader.
    • OS X 10.9 or later is required.
  • 1.6r2 -- 2014-10-01
    • Fixed : A script link of the sample code in the HelpBook does not work.
  • 1.6 -- 2012-11-28
    • "each", "map" and "map_as_list" will be passed contents of elements of a list to "do" handler of a script object intead of references to elements of a list.
      • passing a referece to an element does not work with AppleScriptObjC.
    • Added "enumerate".
    • Added "set_item_at".
  • 1.5 -- 2012-05-27
    • Added "add_from_list".
    • Added "shallow_copy".
    • Added "deep_copy".
    • Added "iterator".
  • 1.4.1 -- 2012-04-21
    • Update Help.
      • Fixed : "Edit Link" and handler's copy link does not work in Mac OS X 10.6.
    • item_at can accept list of indexes.
    • Added as_text_with.
  • 1.4 -- 2010-01-29
    • Removed dependecy on "ShowHelpBook".
    • Added "items_in_range"
    • The "count" command is used to obtain length of a list instead of "length" property in "count_items".
    • ModuleLoader 2.1 or later is required to load "XList".
  • 1.3 -- 2008-03-20
    • Removed dependency on StringEngine
  • 1.2.1 -- 2008.02.02
    • Added exchange_items().
  • 1.2 -- 2008.01.05
    • The handler 'next()' will raise error number 1351 when there is not next element in the list.
      • In the previous version, 'missing value' is returned. But 'missing value' can be accepted as a list element.
  • 1.1.1 -- 2007.12.04
    • Fixed errors of the refernece manual.
  • 1.1 -- 2007.07.10
    • Renamed "SmartList" to "XList"
    • Renamed "next_item" to "next"
    • Added make_with , make, make_with_text, count_items, set_item, index_of, current_index, has_item,as_xtext_with, as_unicode_with, as_string_with
  • 1.0.2 -- 2007.06.01
    • Conetns of a list can be changed by map and each.
      • A reference to an item of a list is passed to do handler.
  • 1.0.1 -- 2007.05.30
    • Added English document
    • Added reset()
    • Added all_items()
    • Added each()
  • 1.0 -- 2007.05.23
    • First Release