MACSCRPT Archives

November 2008

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:
"Mark J. Reed" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Mon, 3 Nov 2008 13:17:44 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (30 lines)
On Mon, Nov 3, 2008 at 11:27 AM, Chuck Pelto <[log in to unmask]> wrote:
> How does one insert data into the middle of an existing list?

One doesn't; one creates a new list with the desired bits of the
original list plus the new data in the correct order.  You can only
add elements to an existing list at the beginning or the end.

> Is there a simple call to do this?

As the other Mark said, it's simple - just not efficient.

> Or do I need to set up a complex handler?

This should work as a generic insertion handler, although I haven't tested it:

to insert anItem into aList at aPosition
    return items 1 through (aPosition - 1) of aList &  anItem & items
aPosition through end of aList
end

set myList to {itemA, {itemM, x}, {itemP, y}}
set myList to (insert itemZ into myList at 2}
myList
-- {itemA, itemZ, {itemM, x}, {itemP, y}}



-- 
Mark J. Reed <[log in to unmask]>

ATOM RSS1 RSS2