Wednesday, October 31, 2012

October 31st



                I enjoyed the tutorial exercises for this week. Initially I was stuck on how to define the functions in questions 9.2.5 and 9.2.6 for odd-numbered strings. I started by defining the function to take the first and last half of my strings and I wrote only check-expects with even-numbered strings.  My definition worked for even-numbered strings so I moved on to try to write it to accept odd numbers too. I looked back at examples and tutorial exercises we had done before, specifically examples on rounding numbers. My research paid off because the definition I wrote works for both even- and odd-numbered strings.

                Project #1 was posted last Friday so I started working on it over the weekend and I completed it today. It wasn't too bad, but I found it a little difficult to try to just jump in and manipulate the code already written. There were a few times that I got stuck but when I did I checked Picturing Programs, the DrRacket Help Desk, and previous tutorial exercises and demos from class. Often I found that checking these resources helped but sometimes I still couldn't get the check-expects to pass. When I got too frustrated with repeated failure I would stop working on it for a few hours, or even the rest of the day, and try again later, which also really helped.

Thursday, October 25, 2012

Models that aren't images?



                 This week when I tried the tutorial exercises it was like I'd forgotten everything we've learned. I was forgetting the basics like brackets and hyphens and I had trouble with the exercises. I had a friend show me what I was doing wrong though and I had no problems after that. I didn't spend enough time playing around in Dr. Racket this week, though, because the quiz threw me off a little. In all of the big-bang exercises we used a function with on-tick in the form of:

                (on-tick function-name interval)

The quiz used a numerical value instead of a function and I wasn't sure what that would produce. An error? Would the program ignore it? After the quiz I tried it to see what really would happen. I am going to practice some more using big-bang with models that are numbers not images to make sure I fully understand what I'm doing and hopefully I won't get stuck on any more quizzes.

              Last week we got our tests back. I'm pretty happy with the mark I got and I'm glad I didn't stress too much over studying. I wrote the test very quickly though, and I ended up missing one question. On the next test I plan to make sure I take my time looking over each question and my answers.

Sunday, October 14, 2012

Another tutorial exercise down...



I started the Dr. Racket exercises for tutorial #4 by practicing the code we had done in class with map and map-image. I created various lists to get familiar with using map and I defined my own function add5, mimicking add1, to add 5 to every number in my list. I also tried the functions previously defined in class (less-green and swap-red-blue) on a new image.  Then I moved on to defining my own functions to change the colours in my selected image. I initially tried to define my function so that red would be removed from every pixel but I was unsuccessful. I kept getting errors like:

                color-red expects a color, given 0

and my check-expect kept failing so finally I gave up trying to eliminate red entirely. Instead I defined my function to mimic less-green, but set red to be the quotient when divided by 10 rather than 2. After this worked I opened the Help Desk from Dr. Racket. I searched until I found an example of how to define a function that produces an image with one colour completely leached out. The definition in the example was written: 

                ; lose red: color -> color
                (define (lose-red old color)
                                (make-color 0 (color-green old-color) (color-blue old-color)))

I followed this example but rather than use 'old-color' I kept what we had used in class, so my function read:

                (define (remove-red c)
                                (make-color 0
                                (color-green c)
                                (color-blue c)
                                (color-alpha c)))

I ran this and applied it to an image. It worked! My test passed and it produced the image I wanted.
                I moved on to the next part of the tutorial, defining rotate-red-blue-green but had an extra set of brackets when I tried to apply it to my image and I kept getting the error:  

                color-green: expects a color, given #<image>

I looked at swap-red-blue and realized I didn't need  the brackets. I deleted them, ran and got the expected image.  I found the tutorial exercises good practice for getting acquainted with using map and map-image on my own.

Friday, October 12, 2012

The Why and How of Slogging

So far I am enjoying the course quite a bit. I have no experience in computer programming despite having a programmer in the family. At first I was unsure what the Dr. Racket demonstrations and tutorial exercises were leading to, but I'm beginning to see some of the possible applications.


I really appreciated the tutorial videos for the first two tutorial exercises. I found that they made learning the material and practicing it in Dr. Racket easier and more straightforward.  I started by watching the video once, and then watching it a second time while practicing the exercise in Dr. Racket in my own window. After I'd done the exercises in the video I tried the suggested exercises listed below each video.  At first I had some trouble defining functions in tutorial 2 to produce precisely what I wanted. I re-watched the videos and kept practicing defining different functions until I got the hang of it.  Of course, since I'm writing this a number of weeks after trying the exercises I don't remember specifically what I was having trouble with. My future entries will have to be written much sooner after trying the tutorial exercises. Regardless, I found that all of the tutorial exercises appropriately prepared me for the first term test this past Wednesday.

I liked seeing the application of what we've learned to create the barracuda "clock" in the Dr. Racket demonstration.  If I have extra time before we cover it in class, I'd like to experiment on my own with what was left on the wish list:

; rotate at the right speed
; rotate from (near) the tail

Changing the rotation speed of the barracuda to the appropriate speed of a clock should be easy now that we covered tick handlers and the interval in tutorial 3. Changing the point of rotation, though, will be something I'll have to look up.

Up until now I have found the Dr. Racket exercises fairly straightforward.  I am eager to start the next tutorial exercises and I look forward to seeing if exercises get more difficult as this course progresses.