Monday, 18 February 2013

AGGREGATES!

This week we learned how to group values into a "list" and then used functions to manipulate that list using "map." This is a very useful idea if you wanted the same function to operate on multiple pieces of data. I found it especially difficult to understand at first, but after some experimenting on DrRacket, I sort of figured it out. I'm beginning to notice that when I play around with DrRacket, I seem to understand course concepts more better. I guess it is better to try coding on your own once you are introduced to a new concept.

Anyway, one problem I encountered when trying to figure out aggregate functions is the following. Use map and a function that you create called sub5 to transform the list (list 1 2 3 4 5) into the list (list -4 -3 -2 -1 0). In order to solve this problem, I had to first figure out how to develop a list with numbers 1 - 5 in order. I remembered from class, Professor Heap mentioned that we can use the range function to develop a list provided we tell the function how much increments the numbers will increase/decrease by. This is what I used: (range 1 6 1). This will tell DrRacket to produce a list of numbers starting from 1 and increasing by 1 until 6, but not including 6. Next, I had to define a function sub5. This wasn't hard at all since I already knew had to define functions from several weeks ago. This is what I used: (define (sub5 num) (- num 5). "num" is used as a placeholder. Lastly, we had to combine both our function and our list using the "map" function which tells DrRacket to use the function sub5 and operate it on every number in our list. This is what I used: (map sub5 (range 1 6 1)). This produced my desired answer.

This was a very interesting concept to learn and I am looking forward to class after reading week!

Thursday, 7 February 2013

Fibonacci Numbers!

I just had my test a couple of hours ago and I feel great. I felt really uncomfortable going into the exam because there was a lot of material. I was afraid there would be a question on Fibonacci numbers on the test, and guess what, IT WAS ON IT. The only reason I don't like dealing with Fibonacci numbers, is because I did not understand the code that was presented. Normally, I understand expressions dealing with images and  simple calculation, but when "if" statement get into the mix, I completely lose my mind. At first glance of the question, I started to panic because I didn't know what to do. So, I tried to understand the question and realized we didn't have to do any coding. All we had to do was explain how the computer deals with Fibonacci numbers. After a long series of steps trying to explain that each Fibonacci number was dependent on previous ones, I was able to figure it out. But, it took me the majority of the test. I just checked the solutions to the problem  and I feel I had done the question correctly. Overall, I fell the test was fair. Glad that their is no tutorial tomorrow because I get to sleep in. See you in my next post.

Friday, 1 February 2013

The "big-bang" theory

This week was really interesting. We've finally moved on from manipulating static images to making small animations. We've learned about a new built in function known as "big-bang." The name itself caught my attention because I frequently watch The Big Bang Theory. The "big-bang" function takes any image and is able to animate the image using functions known as event handlers. An event handlers is somewhat self-explanatory. It just means that it controls the actual event that is occurring in the animation, whether it be a rotation, reflection, how many ticks/per-second, etc.

I actually understood this weeks content and really enjoyed, but one problem I had that was really minor occurred. I had the perfect animation created with a triangle being rotated clockwise, every half second. But, I didn't like the fact when the image was rotating, some parts of the triangle were not being shown. I didn't know how to make the animation window larger. So I toke a wild guess and thought that because (on-draw show-it) is the event-handler that actually produces that image in the window, I thought that I could increase the y-axis of the window by placing a number there to actually see all of our magnificent triangle. It ended up working, and when I actually went to review the Events Video, Professor Heap actually did make his window larger for the fish using the same method. I was really happy. If your interested, I have posted a copy of both the original code and the new code if you would like to see this minor problem. Make sure to to enable picturing-programming on intermediate student with lambda though!

Original: (big-bang (triangle 100 "solid" "black") (on-tick rotate-cw 1/2) (on-draw show-it))
New:     (big-bang (triangle 100 "solid" "black") (on-tick rotate-cw 1/2) (on-draw show-it 100 105))

This week has been a great week, and I am looking forward for next week's lecture and test.