By Developers, For Developers

Historical errata for Learn to Program

PDF PgPaper PgTypeDescriptionFixed onComments
6TYPO

version numbers don’t match up:

mezzaluna:~ chris$ ruby -v
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
So, that’s good; I have Ruby 1.8.1 installed. At this very moment, 1.8.3
is the latest. But 1.8.anything is pretty good. If you have an earlier
version, you can still use it, but a few examples in this book might not
do exactly the same thing for you. (Almost everything should work,
though.)

2009-02-13
30ERROR

Arnt there 11 methods? you said puts, gets, chomp, to_s, to_i, to_f, +, -, *, and /. But when we created variables we used = to define them and wouldn’t that be a method too? I am really new to this so maybe im wrong.

2009-02-13
118TYPO

“daylight savings time, while it was not
dayling savings time when Y2K struck”

dayling should be daylight?

2009-02-13
152TYPO

“To learn more about it, or to subscribe, have a
look at”

this link at the end of this sentence sends you to an error page, but i cant put the link in because of your spam filter

2009-02-13
86ERROR

I have correctly entered this program as instructed and I can’t get the question to recur either in Terminal or in TextMate. I am using a Mac, by the way.

2010-03-09
30SUGGEST

The book asks to list which methods were learned in chapters 1-5 as:
puts
gets
chomp
conversions (.to_s, .to_i, .to_f)
arithmetic (+,-,*,/)

But what about an escape? What does it count as? Maybe it would be worth adding a blurb about escapes in this section.

Awesome book, thanks!

2010-03-09
31SUGGEST

Regarding the first examples starting with:
puts 5.+ 5
puts(‘hello ’.+ ‘world’)
puts((10.* 9).+ 9)

Can you please clarify why simply removing the dot from .+ allows all the above examples to execute without the “warning: parenthesize argument(s) for future version”?

I understand every method is being done by some object, even if it doesn’t have a dot in front of it along with the 5 * ‘pig’ problem but why does removing the dot to the left of the method + allow the method puts and the string/integer objects to execute without the warning above?

I understand the concept of implicit objects and the variable “self” as explained but I’m still confused with the examples above for the reasons described…

Thank you!

2010-03-09
179ERROR

I cannot get the shuffle program “How I would do it” to run under Ruby 1.8.6 Leopard OS X. Error Message: wrong argument type Symbol (expected Proc) (TypeError)

2011-08-23
6TYPO

ruby version numbers in the middle of page (after ruby -v) does not match up. i.e. 1.8.6, then 1.8.1 and then 1.8.3

2010-03-09
35TYPO

Second last sentence on page 35 should read: “They are similar to center, except that they pad the string with spaces on the right and left sides, respectively.”

The way I understand it, ljust justifies to the left, thus adding spaces on the right and rjust does the opposite.

2011-08-23
181ERROR

The “How I would do it” program is wrong. It should be:

def dictionary_sort arr
return arr if arr.length <= 1
middle = arr.pop
less = arr.select{|x| x.downcase < middle.downcase}
more = arr.select{|x| x.downcase >= middle.downcase}
dictionary_sort(less) + [middle] + dictionary_sort(more)
end
words = [’ can’ ,’ feel’ ,’ singing.’ ,’ like’ ,’ A’ ,’ can’ ]
puts(dictionary_sort(words).join(’ ’ ))

2011-08-23
26TYPO

section 5.3 output of “puts gets” is wrong:
#<NoMethodError: private method ‘gets’ called for false:FalseClass>

2010-03-09
27TYPO

Error in program output:
Hello there, and what’s your name?
#<NoMethodError: private method ‘gets’ called for false:FalseClass>

2010-03-09
44-52TYPO

The whole range of pages 44 through 52 has incorrect code output boxes showing “#<NoMethodError: private method ‘gets’ called for false:FalseClass”

2010-03-09
27ERROR

It looks like the example output of the same code are not being produced correctly - I’m seeing ruby interpreter errors instead of the expected output. This is happening in all of Chapter 5 (so far).

2010-03-09
109ERROR

Hi,

I’m a newbie, so I could be wrong about this, but I found what I think is an error on page 113 in the example about moving files using Dir[].

The author’s code is this:

new_name = if pic_number < 10
“batch_name0#{pic_number}.jpg”
else
“batch_name#{pic_number}.jpg”

That moves the files, but names them all “batch_nameXX.jpg”. I wondered if those statements needed to be in the wavy brackets (whatever the hell they’re called), and I changed the code to this:

new_name = if pic_number < 10
“#{batch_name}00#{pic_number}.jpg”
elsif pic_number < 100
“#{batch_name}0#{pic_number}.jpg”
else
“#{batch_name}#{pic_number}.jpg”
end

That code works for me. (I changed it for 3-digit prefixes, but I don’t think that matters). I only know what I’ve learned in this book, so I could be way off base.

Thanks,

Brandon Hays

brandon.hays@gmail.com

2011-08-23
88SUGGEST

Setting aside the fact that the recursion chapter melted my brain, there were two things unexplained by the author in the continent_size example that would have helped a lot:

1.) There’s no explanation of how Ruby handles arrays inside arrays anywhere else in the book, so explaining why you use [y][x] and xy would have helped a lot.
2.) Having the “little guys” fall off the edge of the map returns “nil”. This did not become obvious until a friend pointed it out, and I was finally able to solve the bug.

2010-03-09
50TYPO

output does not match program

2010-03-09
51ERROR

output at top of page 51 does not match program on page 50

2010-03-09
197SUGGEST

The ‘How I would do it’ roman_to_integer program needs the following line at the beginning of the program:

require ‘jcode’

2010-03-09
12TYPO

puts 5 * (12-8) + –15
puts 98 + (59872 / (13*8)) * –51

is the second closing parenthesis after 13*8 incorrect? does not seem to work unless it is removed

13*8)) * –51 when run it returns
syntax error, unexpected ‘)’, expecting $end

puts 98 + (59872) / (13*8)) * –51
^

without puts 98 + (59872) / (13*8) * –51

returns 5
–29227

Regards,
Richard

2010-03-09
119ERROR

The body text, and the example code, say that prof[12,8] and prof[12..20] are the same, but unfortunately that isn’t correct. This can be proven by the test prof[12,8] == prof[12..20]. The variable prof[12..20] contains nine characters, with the ninth character being the space after the word ‘universe’. To make these two sub-strings the same, change prof[12,8] to prof[12,9] or prof[12..20] to prof[12..19].

PS: This is a great book!

2011-08-23
127TYPO

In the second paragraph of section 13.4, the word “keep” is incorrectly shown twice. It says “keep keep” and should just say “keep”.

2011-08-23
172ERROR

The final example on this page doesn’t run, and in fact the output listed in the PDF is an error message.

#<TypeError: wrong argument type Symbol (expected Proc)>

2011-08-23
17SUGGEST

Hello,

It’s called “escaping” because, in the old days, it caused the compiler to escape from the normal processing of characters. which was one at a time in a loop and would lead to the undesired result. The escape character would cause additional processing to kick in.

(In the old days, when computers were much slower and had much less memory, compile time was a critical marketing point. Hence anything to simplify the compiler would improve sales.)

Good Luck. Good Book!

2010-03-09
84ERROR

Exercize 9.5 intructs the reader to get rid of the ‘answer’ variable, however, both solutions on pgs 172, 173 still return this variable.

2011-08-23
90SUGGEST

For those readers unfamilar with the world of computer games, the references and exercizes related to the game “Civilization III” are annoying and obtuse. Such a reader does not want to have to grok the minutia of this game, which the reader has no previous interest in, for the sake of completing the exercize. For future versions of the book, please do your readers a favor and rework the examples with something more universal.

2010-03-09
112TYPO

I don’t know if it’s a typo or a font issue, but at various places the square brackets look instead like parentheses (sp?)…

2010-03-09
50TYPO

What, are you like… by little brother?!

should be:

What, are you like… my little brother?!

2011-08-23
15TYPO

I’ll color strings ‘blue’. should be: I’ll color strings ‘magenta’.

2011-08-23
119SUGGEST

It would be nice to add just one more version of this example with
if name[0] ?C changed to if name[0,1] C
in order to illustrate the first method you mention of getting a substring.

2010-03-09
12ERROR

puts 98 + (59872 / (13*8)) * –51

Using logic and plain desktop calculator, shouldn’t the above yield an integer of –29262 ?

2011-08-25Nope, this is not calculator math; it's integer math. (Keep reading to see how integer divide works and why we might want it.)
109TYPO

Hi,
I guess in the example given, the line for giving pic names should be:

“#{batch_name}0#{pic_number}.mp3”
else
“#{batch_name}#{pic_number}.mp3”

2011-08-25Well... not really. Are your pics really in MP3 format? Because mine are just JPGs.
168ERROR

the version of how i would do it on the roman numeral program returns an incorrect answer. should be same as easy version but is different. would like to see what it takes to correct it.

2011-08-25I wouldn't say it was incorrect, but it is different. The book shows quite clearly that they give different results. But that is "how I would do it"! What can I say... I don't follow instructions very well.
43SUGGEST

Could be me/my setup, but …

In section on math object, these two statements

puts (Math.cos(Math::PI/3))
puts (Math.tan(Math::PI/4))

are said to produce the following rounded results:

0.5
1.0

When I execute on my machine, I get unrounded values:

0.5000000000000001
0.9999999999999999

2011-08-25Yes, and you'll notice that the value of Math::PI is also not totally correct. :-) There is a lot of rounding in floating-point math (and again when displaying floats as strings). It looks like your machine is rounding slightly differently than the build machine used for the book... but it's nothing to worry about.
12SUGGEST

The instructions seem to ask for a single, comprehensive time program rather than individual programs. The solutions you give are individual. A small point, but it caused me to attempt to write something more complex than was necessary, and for which I was not yet expert enough to do in short order. Just a thought.

2011-08-25Unless more people have a problem with this, I will probably leave it as it is (though I can see the possible confusion). Thanks for the thought, though. :-)
12ffSUGGEST

TheThese are errata in the errata, not in the book. You
have done good work in the book.

My copy of the paper book identifies itself as “P2.0
printing, April 2010”. My setup is MEPIS 8.5 on an HP
Pavillion dv6911us running ruby 1.8.7 (2008-08-11
patchlevel 72) [x86_64-linux] obtained from the MEPIS
repositories.

p 12\tkcalc on MEPIS 8.5 gives –29262 as Ray said, but
\truby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
\tgives –29227 as the book says.

p 43\tMy set-up (see above) gives rounded results.

p 84\tThe erratum which Cosmo Lee reported is not in
my copy.

2011-08-25As I mentioned to Ray, the calculations are not the same as what a calculator does, so it is not an error. \n \nIf you want to get something "like a calculator", use floats.
2OK

I downloaded the Ruby language as directed (url is incorrect but google directed me to the correct place) and it is supposed to come with Scite (text editor). If it did I cannot find it. I didn’t even know what a text editor was but I did succeed in finding Scite and got it downloaded and hopefully working.

2011-10-14
61SUGGEST

Deaf Grandma extended exercise states that when you shout BYE, Grandma should pretend not to hear you. This reads like she should be silent in response to BYE, but the answer provided in the back shows that she gives her normal response. Exercise instructions could be a bit clearer.

2011-08-25It's a good point, and I didn't realize there was a different way to interpret it. However, as with all of these exercises, I don't so much care that you get "the" right answer... if you wrote a program that did what you intended for it to do, then you are programming! Congratulations! :-)
199ERROR

For the ‘How I would do it’ solution to the Interactive Baby Dragon exercise, a possible command given is ‘put to bed’, but the code only works if the user enters ‘put_to_bed’.

2011-10-14Good catch!
6149ERROR

On page 61 of the PDF book (or 49 in the paper book), you state that you cannot define rand within a parameter that doesn’t start at zero. While that may be true in context of what the reader currently knows (and you may already know and acknowledge this), but that’s not entirely true! You can actually define rand’s parameters with by doing something like this:

rand(1938..1985)

This will allow your lovable deaf gramma to accurately recall her memories like only a deaf gramma can without too much hassle with working around in the code formulating other, longer solutions.

Hope this helps!

2013-06-13
92TYPO

The second exercise under “11.8 A Few Things to Try”
Second sentence: “We’ve ripped a 100 or so CDs…”

You don’t need that “a” right there.

Other than that, the book is great! I’m loving it a learning a ton!

2013-06-13
148ERROR

Unused variable “bottles = ” in:

num_at_start.downto(2) do |num|
bottles =
…
end

2013-06-13
148TYPO

“that” should be “than” in:

“It’s a bit more complex that the other examples here, partly because it’s a real, working tool.”

2013-06-13
98ERROR

Book states “You might have noticed
that when we used each, the objects in the hash didn’t come out in the same order we put them in. (I mean, they could, I suppose…it’s technically possible. They just don’t usually.)” but as of Ruby 1.9 hashes now keep insertion order. (see www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ )

2013-06-13
87TYPO

Text halfway down page reads “Viola!” While this is a recognized English word, it ought to read “Voila!”

116TYPO

“. However, none of these is actually called until the very last line.)”

Shouldn’t it be “none of these are”?

56TYPO

For the example ‘favorite things’, should be ‘whiskers on kittens’… whiskey on kittens is just cruel. :)

\\ / \\
) ( ’ )
( / )
\\ ()|

2014-04-06
66ERROR

In the method ‘ask’ the answer variables are declared in the private scope of an ‘if’ then used later as the return at which point it is inaccessible.

I think it should be something like….

def ask question
answer # declare the variable to return

while true
puts question
…
end

answer # return true or false depending on what the user entered
end

61SUGGEST

Chapter on Methods does not use the community accepted Ruby Style Guide of encasing parameters in parenthesis. Parenthesis are only left off of methods if there are no arguments. The lack of parenthesis makes the code examples difficult to read with no benefit. Please see the Ruby Style Guide listed on github

20ERROR

Sorry the page number is incorrect - i am reading using the kindle cloud reader.

Two serious issues:

(1) the author’s email address needs to be here so that people can ask questions.

(2) start of chapter 2 - in the hello world ruby program. in order for it to run - if you are a linux user - the terminal must be in the same directory as the ruby code. duh! but the author doesn’t specify this, and a noob user would know any better and his/her code simply would not run. this is frustrating because we are paying good money for a book so that it lays things out in a easy to read/learn manner.

pls take this feedback on board.

rgds

Ben

141TYPO

The answer (“How I would do it”) to the “modern roman numeral” question was “MIM”, when it should be “MCMXCIX”, which represents the year 1999 as in “puts(roman_numeral(1999)) ”.

Thank you for your work!

64TYPO

It seems like the blank lines that are present in the representation of screen output disappear in the epub version of the text. For example, in the pdf is looks like this (dashes represent highlighting)
———————————————
This puts returned:


but in the epub it looks like:
———————————————
This puts returned:
———————————————

51ERROR

In the 2nd paragraph from the bottom, the last sentence is “(Even if we were to set flavor to point to something else later in the program, that wouldn’t change the array.)” Here is an irb session that seems to contradict this sentence:
$ irb
irb(main):001:0> flavor = ‘vanilla’
=> “vanilla”
irb(main):002:0> a = [89.9, flavor, [true, false]]
=> [89.9, “vanilla”, [true, false]]
irb(main):003:0> flavor = ‘chocolate’
=> “chocolate”
irb(main):004:0> a = [89.9, flavor, [true, false]]
=> [89.9, “chocolate”, [true, false]]
irb(main):005:0>

Categories: