MACSCRPT Archives

July 2007

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Gary (Lists)" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Fri, 27 Jul 2007 17:12:29 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (48 lines)
"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

ATOM RSS1 RSS2