"RJay Hansen" wrote:
> I want to create a list containing other lists but can't seem to
> figure out how to do it. When I create a new, empty list then try to
> add already-created lists, those lists lose their "listness", i.e.
> their contents just become items in the new list. For example:
>
> set thisList to {1, 2, 3}
> set thatList to {"a", "b", "c"}
> set bothLists to {}
> set bothLists to ((bothLists & thisList) & thatList)
set bothLists to thisList & {thatList}
> ---> {1, 2, 3, "a", "b", "c"}
>
> but I want to get:
>
> ---> {{1, 2, 3}, {"a", "b", "c"}}
>
> Can this be done?
Yes, but you have to follow AppleScript's rules. ;)
set _list1 to {1, 2, 3}
-- {1, 2, 3}
set _list2 to {"a", "b", "c"}
-- {"a", "b", "c"}
set _list3 to _list1 & _list2 -- make a list out of two lists
-- {1, 2, 3, "a", "b", "c"}
set _list3 to _list1 & {_list2} -- add a list to a list
-- {1, 2, 3, {"a", "b", "c"}}
copy _list2 to end of _list1 -- add a list to a list
-- {1, 2, 3, {"a", "b", "c"}}
copy {"x", "y", "z"} to item 2 of _list1 -- replace an list item with a list
-- {1, {"x", "y", "z"}, 3, {"a", "b", "c"}}
--
Gary
|