Wednesday, 30 October 2013

Assignment 1 and Recursive Functions (Part 2)

I have finally found the root of the error for assignment 1!! Following professor Heap's suggestion I removed all modifications that I made to the original code (at least I thought I did) and started making changes to the code one bit at a time testing those changes out along every step. Soon I noticed that even the base code without any changes yielded the error. This led me to compare the base code that I had to the one posted online, and the bug was finally caught: it was a tiny line "(require racket/list)" that I added earlier to test out some commands but forgot to remove after the fact. It loads an additional module that provides additional functionality for manipulating list, but somehow it interferes with the base code and culminates in an error. The lesson learned? Always clean up after you mess around!

A small demonstration of the completed code that simulates an epidemic:


Also the exercise on recursion we did in lecture today was super helpful. It seems that the best way to predict the result of a recursive function is to work out the smallest unit of output possible, then work your way up through increasingly larger inputs, using what you already know about the output of the previous input, and eventually arriving at the output for your desired input. The previously elusive structures of recursive functions now finally make sense! I think this really shows how tracing codes is instrumental in the understanding of a particular programming language.


P.S. I got an A+ for the term test!! I'm so indulging myself with a few hours of gaming tonight ;)

Saturday, 26 October 2013

Assignment 1 and Recursive Functions (Part 1)

Alright, let me just say that the moment I opened sneeze.rkt, I totally blanked out as none of the codes seemed to make any sense to me. However, the function contracts and check-expects have been incredibly helpful since they together give a very good indication of what the function does, what is the input, what is expected, etc. I'm going to follow this practice from now on and I think everyone should get into the habit of doing it as well, as they make reading the code much easier when you come back to it after a while.

The assignment overall wasn't hard. Professor Heap basically has done all the hard parts and we only needed to fill in some holes. Unfortunately when running the program some error appeared and seemed to stem from the original code provided to us. Debugging did not work it's magic, so I'm turning to Professor Heap for help. We'll see what the problem is.



On last thought, one of the things that really amazed me from the 2 weeks of lectures was the concept of recursion: basically a function that calls itself, creating a loop. It seemed such a simple idea and yet is so elegant and powerful. Examples shown in lecture had so few lines of codes yet could achieve such complicated tasks as predicting the folding patterns of a strip of paper after, say, 100 folds.

Friday, 25 October 2013

First Blogger Post!

Just finished WikiII and started on assignment 1. Off to bed!

Feeling sleepy....zzzzzz....

This blog will record my journey through my first computer science course at the University of Toronto. The programming language referred to in this blog is Dr.Racket.