crashing recursion 
Author Message
 crashing recursion

Hi all,

I'm Ian Varley, a recent addition to this list. I have a question
regarding Microworlds for Mac. Every time I run the following
recursive program to "race" 5 turtles across the screen, my computer
crashes right at the end (I get the bomb and the helpful "restart"
button). Anyone have any idea why it might happen? The program seems
to be working correctly, other than that crashing part. My best guess
would be that there's a bug in the memory allocation for variables
("let") within recursive procedures, but that's totally just a guess.

Thanks!
Ian Varley

Woodside Priory School, Portola Valley, CA

to race
everyone [right 180 ]  ;; turn around each time
  talkto "t1 launch [restOfTheWay 300]
  talkto "t2 launch [restOfTheWay 300]
  talkto "t3 launch [restOfTheWay 300]
  talkto "t4 launch [restOfTheWay 300]
  talkto "t5 launch [restOfTheWay 300]
end

to restoftheway :amount
     if :amount > 0 [
         let [distance random :amount]
         glide :distance 1
         restoftheway :amount - :distance
     ]
end

To unsubscribe from this group, send an email to:

LogoForum messages are archived at:
http://www.*-*-*.com/

Your use of Yahoo! Groups is subject to http://www.*-*-*.com/



Sat, 29 May 2004 12:10:38 GMT  
 crashing recursion

I tested your procedure using Microworlds under MS Win98, and think I see
the problem.

Your assignment of "distance" as random :amount will NEVER get to the value
of zero!

RANDOM provides a number _LESS_ than the value of its input, so when
:amount is one, random 1 always evaluates to zero, and distance gets set to
"0".

With distance at "0", your recursive call "restoftheway :amount -
:distance" will always parse to "restoftheway 1" and never decrement to the
magic "0" value.

This causes your recursion to continue in an infinite loop until some
unspecified resource is exhausted. You could see this with a "show (se who
pos :amount)" statement prior to the recursive call.

Reset your IF statement to         if :amount > 1 [ is a quick solution.

Randal T. Wortman

Quote:
-----Original Message----- From: Ian Varley



Subject: [LogoForum] crashing recursion

Hi all,

I'm Ian Varley, a recent addition to this list. I have a question
regarding Microworlds for Mac. Every time I run the following  recursive
program to "race" 5 turtles across the screen, my computer  crashes right
at the end (I get the bomb and the helpful "restart"  button). Anyone have
any idea why it might happen? The program seems  to be working correctly,
other than that crashing part. My best guess  would be that there's a bug
in the memory allocation for variables  ("let") within recursive
procedures, but that's totally just a guess.


Portola Valley, CA

to race everyone [right 180 ]  ;; turn around each time   talkto "t1 launch
[restOfTheWay 300]   talkto "t2 launch [restOfTheWay 300]   talkto "t3
launch [restOfTheWay 300]   talkto "t4 launch [restOfTheWay 300]   talkto
"t5 launch [restOfTheWay 300] end

to restoftheway :amount      if :amount > 0 [          let [distance random
:amount]          glide :distance 1          restoftheway :amount -
:distance      ] end

To unsubscribe from this group, send an email to:

<http://groups.yahoo.com/group/LogoForum
TARGET="_blank">http://groups.yahoo.com/group/LogoForum

Your use of Yahoo! Groups is subject to <http://docs.yahoo.com/info/terms/
TARGET="_blank">http://docs.yahoo.com/info/terms/

To unsubscribe from this group, send an email to:

LogoForum messages are archived at:
<http://groups.yahoo.com/group/LogoForum>
http://groups.yahoo.com/group/LogoForum

  Your use of Yahoo! Groups is subject to the
<http://docs.yahoo.com/info/terms/> Yahoo! Terms of Service.



Sat, 29 May 2004 12:19:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. crashing recursion

2. RECURSION RECURSION RECURSION ... AAARRGGHHHH

3. Python crashes (deep recursion ?)

4. Tail recursion and complete recursion?

5. Ariane Crash (Was: Adriane crash)

6. OO, lexical scope, closure, tail-recursion, continuation

7. Question about recursion in J

8. Lisp type list, recursion and tail call optimisation

9. Recursion

10. Block recursion in Dolphin.

11. Recursion in Smalltalk

12. Tail recursion ???

 

 
Powered by phpBB® Forum Software