Strange errors on Mac OS X

I was wondering if anyone could help out a newbie in need. So I've just
started learning Ruby, my first programming language. I've been going
through this online book, and when running one of the programs from the
book, I've been encountering a strange error. The program can be found
here (it's the one that writes numbers out in English), or you can check
out the attachment, where I've included it:

http://pine.fm/LearnToProgram/?Chapter=08

I was running it unchanged from the website. I've tested it out on three
computers, all Macs, but I always get this error:

numwrite.rb:1: syntax error
    # Now here- write*100 # Subtract off those hundreds.ite
out?ut.n',
                             ^

The line of code it shows is gibberish, it seems to be made up of
several lines of code mixed together. I've tested it on a Powerpc eMac
running OS X 10.2 and Ruby 1.8.2, an Intel Macbook running 10.4 and Ruby
1.8.6, and a Powerpc iBook running 10.4 and (I think) Ruby 1.8.4. All of
these give me something similar to this error.
Does anybody know what is going on, and can help, please?

Attachments:
http://www.ruby-forum.com/attachment/1085/numwrite.rb

···

--
Posted via http://www.ruby-forum.com/.

Hi Gabriel - I just copied and pasted your attachment and it ran
without any issues on my laptop, a MacBook Intel Core Duo running OS X
10.4.11 (bought nearly exactly one year ago). I ran it through two
versions of Ruby, 1.8.4 and 1.8.6, both were fine.

It looks like something weird is going on, wish I could be more
specific. There's nothing wrong with the code that I can see.

···

--
Giles Bowkett

Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com

On 12/2/07, Gabriel N. <gabrielbn@hotmail.com> wrote:

I was wondering if anyone could help out a newbie in need. So I've just
started learning Ruby, my first programming language. I've been going
through this online book, and when running one of the programs from the
book, I've been encountering a strange error. The program can be found
here (it's the one that writes numbers out in English), or you can check
out the attachment, where I've included it:

Writing Your Own Methods - Learn to Program

I was running it unchanged from the website. I've tested it out on three
computers, all Macs, but I always get this error:

numwrite.rb:1: syntax error
    # Now here- write*100 # Subtract off those hundreds.ite
out?ut.n',
                             ^

The line of code it shows is gibberish, it seems to be made up of
several lines of code mixed together. I've tested it on a Powerpc eMac
running OS X 10.2 and Ruby 1.8.2, an Intel Macbook running 10.4 and Ruby
1.8.6, and a Powerpc iBook running 10.4 and (I think) Ruby 1.8.4. All of
these give me something similar to this error.
Does anybody know what is going on, and can help, please?

Attachments:
http://www.ruby-forum.com/attachment/1085/numwrite.rb

--
Posted via http://www.ruby-forum.com/\.

Might be that your code is using carriage returns instead of linefeeds
as end-of-line delimiters. Not sure about Ruby, but I know Python only
recognises LFs as linebreaks. Prior to OS X, Mac OS used CRs as
standard, and some Mac apps still do.

HTH

has

···

On 3 Dec, 04:07, "Gabriel N." <gabrie...@hotmail.com> wrote:

The line of code it shows is gibberish, it seems to be made up of
several lines of code mixed together.

--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org

If you copy and paste text from a website, particularly when is has
been syntax colored and otherwise formatted, you can occasionally get
junk characters. (Most commonly, non-breaking spaces look like spaces
in your text editor but have a different ascii value, and confuse the
interpreter.)

Did you copy and paste the colored text from the website?

···

On Dec 2, 9:07 pm, "Gabriel N." <gabrie...@hotmail.com> wrote:

I was wondering if anyone could help out a newbie in need. So I've just
started learning Ruby, my first programming language. I've been going
through this online book, and when running one of the programs from the
book, I've been encountering a strange error. The program can be found
here (it's the one that writes numbers out in English), or you can check
out the attachment, where I've included it:

Writing Your Own Methods - Learn to Program

I was running it unchanged from the website. I've tested it out on three
computers, all Macs, but I always get this error:

Gavin Kistner wrote:

Did you copy and paste the colored text from the website?

Yes, yes I did. After seeing this, I tried copy-pasting a non-break
space and using find/replace to replace them with normal spaces, but it
seems as though the text editor doesn't differentiate between non-break
spaces and normal ones, as it was telling me that every space was a
non-break space, even after I replaced them. I am still getting the
error. This sounds plausible, though, are there any other characters
that, coming from websites, break Ruby?

Might be that your code is using carriage returns instead of linefeeds
as end-of-line delimiters. Not sure about Ruby, but I know Python only
recognises LFs as linebreaks. Prior to OS X, Mac OS used CRs as
standard, and some Mac apps still do.

I've been using Textedit, if that's any help, in plain text mode. Though
honestly, I have no clue what you're talking about.

···

--
Posted via http://www.ruby-forum.com/\.

No mac apps use CR as line endings now. That went away with OS9's demise.
OS X and native apps all use Unix line endings as standard and as defaults.
That means what you call LF, or line feed, or \n

···

On Dec 3, 2007, at 6:44 AM, has wrote:

On 3 Dec, 04:07, "Gabriel N." <gabrie...@hotmail.com> wrote:

The line of code it shows is gibberish, it seems to be made up of
several lines of code mixed together.

Might be that your code is using carriage returns instead of linefeeds
as end-of-line delimiters. Not sure about Ruby, but I know Python only
recognises LFs as linebreaks. Prior to OS X, Mac OS used CRs as
standard, and some Mac apps still do.

Alright, thanks for helping me narrow it down. I managed to make it work
by retyping the program myself rather than copy-pasting. I guess it was
some "junk" character coming off the website that was confusing the
interpreter. It's working fine now, and I can get on with learning Ruby.
A huge thank you to everyone who replied. :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

Just replace

def englishNumber number

with

def englishNumber(number)

... in this case Ruby shouldn't care about LineFeeds and/or CarriageReturns.

Cheers
Florian

Ruby with camelCase... yuck!

Some Carbon apps that date back to pre-OS X days still use CRs by
default (I use one such app here, and its habit of changing my line
endings is pretty annoying). Some modern text editors, e.g.
TextWrangler, allow you to set the linebreak style along with other
stuff like encodings.

The OP's using TextEdit, which uses LFs by default, although I can't
recall if it preserves existing CRs in pasted text. Might be worth
trying a better text editor to see if that unearths any hidden nasties
- e.g. TextWrangler costs nothing, can display hidden characters and
lets you force line endings to the desired Unix style. And maybe take
a look at <http://en.wikipedia.org/wiki/Newline&gt; if still confused by
my last attempt to explain linebreak issues.

HTH

has

···

On 4 Dec, 00:36, John Joyce <dangerwillrobinsondan...@gmail.com> wrote:

No mac apps use CR as line endings now.

You shouldn't have had to retype by hand. Your code editor should be able to that for you. It should have a command like "Convert to ASCII" or "Zap Gremlins" or something similar. All the code editors that support Ruby that I am familiar with have such a command. TextWrangler, which is freeware, has both. Which editor are you using?

Regards, Morton

···

On Dec 8, 2007, at 3:11 PM, Gabriel N. wrote:

Alright, thanks for helping me narrow it down. I managed to make it work
by retyping the program myself rather than copy-pasting. I guess it was
some "junk" character coming off the website that was confusing the
interpreter. It's working fine now, and I can get on with learning Ruby.
A huge thank you to everyone who replied. :slight_smile:

def englishNumber number

with

def englishNumber(number)

... in this case Ruby shouldn't care about LineFeeds and/or CarriageReturns.

I thought that might be the issue, too, but it ran without my needing
to edit that.

···

--
Giles Bowkett

Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com

Florian Aßmann wrote:

Just replace

def englishNumber number

with

def englishNumber(number)

Just tried it, it's still giving me the error message.
I had a friend running 10.5 and Ruby 1.8.6 try it out on his computer,
and he got the error as well.
His error gives a bit more detail though:

numwrite.rb:1: syntax error, unexpected kIF_MOD, expecting '\n' or ';'
# Now here- write*100 # Subtract off those hundreds.ite out?ut.n',

(Note: I deleted the little pointer (^) under the line because the app
he used to send it to me removed all the spaces, making it uselessly
point to the beginning of the line.)
Hope that helps.

···

--
Posted via http://www.ruby-forum.com/\.

Morton Goldberg wrote:

Which editor are you using?

Textedit, in plain text mode, which isn't really a code editor, but has
been working fine for me so far. I assume it doesn't have this feature.
(I did do a search for "ASCII" in the help files, no match.)
Unfortunately, the computers I'm using aren't really mine, so I don't
want to load them with random software. I may download TextWrangler some
time in the future though, after this mess.

···

--
Posted via http://www.ruby-forum.com/\.

Try this. Go to the link you originally sent us:

http://www.ruby-forum.com/attachment/1085/numwrite.rb

Then click it with your mouse, select everything, and hit command-C to copy it.

Then open up TextMate, or vi, or whatever, save it, and see if that file runs.

That's what I did, and it worked. If it doesn't work for you, then
there's something crazy wiggy with your box. If it does work for you,
then problem solved.

···

On 12/3/07, Gabriel N. <gabrielbn@hotmail.com> wrote:

Florian Aßmann wrote:
> Just replace
>
> def englishNumber number
>
> with
>
> def englishNumber(number)

Just tried it, it's still giving me the error message.
I had a friend running 10.5 and Ruby 1.8.6 try it out on his computer,
and he got the error as well.
His error gives a bit more detail though:

numwrite.rb:1: syntax error, unexpected kIF_MOD, expecting '\n' or ';'
# Now here- write*100 # Subtract off those hundreds.ite out?ut.n',

(Note: I deleted the little pointer (^) under the line because the app
he used to send it to me removed all the spaces, making it uselessly
point to the beginning of the line.)
Hope that helps.
--
Posted via http://www.ruby-forum.com/\.

--
Giles Bowkett

Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com