Re: Removing items from a list
Re: Removing items from a list
- Subject: Re: Removing items from a list
- From: Michael Terry <email@hidden>
- Date: Sat, 6 Mar 2004 15:51:50 -0800
On Mar 6, 2004, at 2:35 PM, Steve Meyer wrote:
Using recursion and the remarkable "rest of" command, and directly
plagiarizing Matt Neuburg and AS:The Definitive Guide (page 153):
The only problem with using recursion in AS like folks do in Lisp is
that one quickly runs into stack overflow errors.
on newListOfSize(len, filler)
set lst to {filler}
repeat until (count lst) > len
set lst to lst & lst
end repeat
return lst's items 1 thru len
end newListOfSize
on deleteItems(theSet, DeleteThese)
if theSet = {} then return theSet
if item 1 of theSet is in DeleteThese then
return deleteItems((rest of theSet), DeleteThese)
else
return {item 1 of theSet} & deleteItems((rest of theSet), DeleteThese)
end if
end deleteItems
set x to newListOfSize(500, 1)
set x's end to "1"
deleteItems(x, {"1"})
-- on my machine, errors with a stack overflow
My brother told me this must mean that AS isn't tail-end recursive or
something. However, I don't know what that means.
Mike
Curious:
--
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopq
rstuvwxyz{|}~
!"#
$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTU
VWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
--
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.