Sunday, 2 December 2012

Final Tutorial Worksheet

I began working on tutorial #9. As I was working on the definition for spiral, I encountered a problem... Dr. Racket asked me to increase the memory that it uses. I followed Dr. Racket's requests and increased the memory. Then I ran the program again. A few seconds later, another message popped up, again asking me to increase the memory. I continued to do this for a couple more times, knowing the something was wrong, but not knowing what to do about it. My computer started acting weird, and started shutting down all of the programs. I sat there very confused since this had never happened to me before.

Later that day, I was going to see Prof Heap to ask a couple of questions about project #2. I decided to show him the definition I was working on. He continued on to suggesting why I was having those errors...

The moral of the story is, when you are doing recursion, you have to make sure that there is a condition. My definition did not have a condition in it and therefore it continuously was programmed into the computer but had no signal to stop. By making a baseline condition, you are giving the computer a way to output the information, without a condition, the computer just keeps going in circles.. OPPSS. Lets just say I learned a big lesson today.

In the long run, I am happy that I made that mistake, because now I will never forget that a recursive function needs a condition!


(define (spiral n)
  (cond
    [(equal? n 0) (vertical-line 10)]
    (else
     (beside/align
      "bottom"
      (vertical-line (+ 10 (* 2 n)))
      (rotate 90 (spiral (- n 1)))))))
                    

No comments:

Post a Comment