[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Strange errors on Mac OS X.

Gabriel N.

12/3/2007 4:08:00 AM

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/?...

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-...attachment/1085/n...

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

13 Answers

Giles Bowkett

12/3/2007 4:32:00 AM

0

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.bl...
Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles....

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:
>
> http://pine.fm/LearnToProgram/?...
>
> 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-...attachment/1085/n...
>
> --
> Posted via http://www.ruby-....
>
>

hengist podd

12/3/2007 12:41:00 PM

0

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.

HTH

has
--
http://appscript.sourc...
http://rb-appscript.rub...

Phrogz

12/3/2007 2:57:00 PM

0

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:
>
> http://pine.fm/LearnToProgram/?...
>
> I was running it unchanged from the website. I've tested it out on three
> computers, all Macs, but I always get this error:

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?

Gabriel N.

12/3/2007 11:02:00 PM

0

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-....

Florian Aßmann

12/3/2007 11:19:00 PM

0

Just replace

def englishNumber number

with

def englishNumber(number)

=2E.. in this case Ruby shouldn't care about LineFeeds and/or CarriageRet=
urns.

Cheers
Florian

Ruby with camelCase... yuck!


John Joyce

12/4/2007 12:36:00 AM

0


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.
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


Giles Bowkett

12/4/2007 12:57:00 AM

0

> 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.bl...
Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles....

Gabriel N.

12/4/2007 1:07:00 AM

0

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-....

Giles Bowkett

12/4/2007 6:49:00 AM

0

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

http://www.ruby-...attachment/1085/n...

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 ru=
ns.

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=DFmann 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-....
>
>


--=20
Giles Bowkett

Podcast: http://hollywoodgrit.bl...
Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles....

hengist podd

12/4/2007 2:39:00 PM

0

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

> No mac apps use CR as line endings now.

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/N... if still confused by
my last attempt to explain linebreak issues.

HTH

has