Re: Recursion and Stack overflow
Re: Recursion and Stack overflow
- Subject: Re: Recursion and Stack overflow
- From: Emmanuel LEVY <email@hidden>
- Date: Fri, 4 Dec 2009 13:52:08 +0100
Maybe you get higher performance if you don't log stuff:
on addone(x)
try
return 1 + addone(x)
end try
return x
end addone
addone(0)
--> 246715
(run in Smile)
Emmanuel
On Dec 4, 2009, at 1:03 PM, Axel Luttgens wrote:
Le 3 déc. 2009 à 19:49, Justin Laden a écrit :
Hi everyone,
[...]
Clearly complicated--and better done in another language--but is
there
any way around the Stack overflow error? What are the limits of
recursion in AppleScript?
Any help would be appreciated, especially if Mr. Neuburg or Mr.
Berkowitz or any other advanced AppleScripters could shed some light
on the deeper recursion issue.
Hello Justin,
Ed already provided some hints wrt that question.
And perhaps could you also conduct some experiments, and get by
yourself a flavor of those limits; for example:
on StupidlyRecurse(Cnt)
log Cnt
StupidlyRecurse(Cnt + 1)
end StupidlyRecurse
on AnotherStupidRecursion(Cnt, Lst)
log Cnt
AnotherStupidRecursion(Cnt + 1, Lst & Cnt)
end AnotherStupidRecursion
on YetAnotherOne(Cnt, Lst1, Lst2)
log Cnt
YetAnotherOne(Cnt + 1, Cnt & Lst1, Lst2 & Cnt)
end YetAnotherOne
on AsWellAsThisOne(Cnt, Lst1, Lst2)
log Cnt
AsWellAsThisOne(Cnt + 1, Cnt & Lst1, Lst2 & Lst1)
end AsWellAsThisOne
-- Run one of these while looking at the events log
--StupidlyRecurse(1)
--AnotherStupidRecursion(1, {})
--YetAnotherOne(1, {}, {})
--AsWellAsThisOne(1, {}, {})
For example, it appears that the compiler doesn't optimise for tail
recursion.
The same way, in the simplest case (the first one), I am limited
here to 621 nested calls; should you imperatively need several
thousands, then clearly AppleScript wouldn't be the right tool.
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden