• 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: Axel Luttgens <email@hidden>
  • Date: Fri, 4 Dec 2009 13:03:02 +0100

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

  • Follow-Ups:
    • Re: Recursion and Stack overflow
      • From: Emmanuel LEVY <email@hidden>
References: 
 >Recursion and Stack overflow (From: Justin Laden <email@hidden>)

  • Prev by Date: [ann] py-appscript 0.21.0
  • 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