• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Recursion and Stack overflow
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recursion and Stack overflow


  • Subject: Re: Recursion and Stack overflow
  • From: Paul Skinner <email@hidden>
  • Date: Fri, 04 Dec 2009 11:22:29 -0500

In Script Debugger / 10.5.1

on addone(x)
	try
		return 1 + addone(x)
	end try
	return x
end addone

addone(0)
-->473

On Dec 4, 2009, at 7:52 AM, Emmanuel LEVY wrote:

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 (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 (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
  • Follow-Ups:
    • Re: Recursion and Stack overflow
      • From: Emmanuel LEVY <email@hidden>
    • Re: Recursion and Stack overflow
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Recursion and Stack overflow (From: Justin Laden <email@hidden>)
 >Re: Recursion and Stack overflow (From: Axel Luttgens <email@hidden>)
 >Re: Recursion and Stack overflow (From: Emmanuel LEVY <email@hidden>)

  • Prev by Date: Re: Finder Comment
  • Next by Date: Re: Recursion and Stack overflow
  • Previous by thread: Re: Recursion and Stack overflow
  • Next by thread: Re: Recursion and Stack overflow
  • Index(es):
    • Date
    • Thread