Chapter 4

Chapter 4 was a interesting chapter and I had a few rough spots figuring it all out.

I first had a small issue with the section on Scope. Mostly what I struggled with was that I copied the code verbatim from the book and I got an error message. I then recopied it to double check, next I had two people read over for me and both of them agreed it was properly copied. In Montfort’s example he has scoped_example(2,4) call the function. However we never defined scope_example we just defined scoped. So I did this instead:

scoped

And it worked so I believe I understand scope now, but at the time it was a bit confusing.

At this point in the book we dove into more terminology and how to use scope, string and lens functions. With the exception of the scope hiccup I was feeling pretty confident at this point, but again I had a little hiccup.

I followed the instructions in the chapter and typed in the below code. My issue was that the book made it sound as if this code was supposed to produce an answer after I entered it in. Since it was supposed to demonstrate that you could write code that was not a function but that still worked. I was confused because my code just stayed and did not produce and answer, and because it was not a function I was unsure how to properly call that answer.

4-4

Even though I could not figure out why it was not doing what I thought it should be I still got the sections overall lesson, always write functions it makes your life less confusing.

After my first problem with getting the scope function to work I tried to focus on making sure that everything was always defined properly so most of my guesses on what would happen when I tried different function modifications was that they would not work properly. Despite the small issues I had so far with chapter 4 I was able to get beyond those problems.

By the time I got to the exercise point in the chapter I figured that I had a better understand of how to write functions. While I was not wrong I think I gave myself too much credit. The first exercise said to “define positive(), a function that takes a sequence as an argument and counts up and returns how many positive numbers (numbers greater than 0) are in that sequence” (Montfort 77)

After that you were supposed to get to the pulse function. However I have yet to get that far but am still trying. Currently this is my function that works the best at producing an outcome:

screen-shot-2016-10-10-at-11-02-37-pm

 

Note I said an outcome not the right one but it is a valid function. At least it is giving me the correct number of counts in the sequence though I have yet to figure out how to count just the positive ones. Here below are 4 random samplings of things I tried to do to make it work properly. (I thought it excessive to include all of the many mistakes, but here are some of them for reference.)

screen-shot-2016-10-10-at-11-05-26-pm screen-shot-2016-10-10-at-11-05-07-pm screen-shot-2016-10-10-at-11-04-54-pm

 

 

screen-shot-2016-10-10-at-11-05-21-pm

 

I am still currently working on figuring out the positive function and hopefully will have it sorted by class tomorrow and then also have the pulse function down as well!

I did however skip over and do the free project at the end of the chapter. The assignment was to change the aspect significantly but also keep most of it the same. So I decided to have the variable result = [0] instead of result = [] This made it so that the function stayed as a doubling function but it changed the list for every result. By adding zero into each list it changed the nature of the result but kept the original intention.

the-new-double

Update: I figured out how to make it run properly I had indented result where I should not have.

positive-correct

(In the future hopefully my blog posts chapters will not be this tediously long due to errors. But it is a learning process and I am certainly learning.)

Leave a Reply