[BUG] "illegal radix 1"

$ ruby -v
ruby 1.8.0 (2002-12-24) [sparc-solaris2.8]
$ irb

“2”.to_i *1.1
ArgumentError: illegal radix 1
from (irb):2:in `to_i’
from (irb):2
“2”.to_i * 1.1
=> 2.2

Notice the difference:

  • “2”.to_i *1.1
  • “2”.to_i * 1.1

That space after “*” makes all the difference.

···


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Hi,

···

In message "[BUG] “illegal radix 1"” on 03/04/11, Daniel Carrera dcarrera@math.umd.edu writes:

“2”.to_i *1.1
ArgumentError: illegal radix 1
from (irb):2:in `to_i’
from (irb):2
“2”.to_i * 1.1
=> 2.2

“2”.to_i *1.1 is parsed as “2”.to_i(*1.1). Try -w if you have doubt.

						matz.

“2”.to_i *1.1
ArgumentError: illegal radix 1
from (irb):2:in `to_i’
from (irb):2
“2”.to_i * 1.1
=> 2.2

“2”.to_i *1.1 is parsed as “2”.to_i(*1.1). Try -w if you have doubt.

Yes, I figured it was something like that. But don’t you think that Ruby
should be able to figure that out?
I don’t know. I don’t think I’ve seen this problem in other high-level
languages. I guess that this is part of how I would expect a high-level
language to “stay out of my way” and let me focus on the problem I am
actually trying to solve.

···


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

quintessence: quintessence (kwin-TES-ens) noun

  1. The pure, concentrated essence.

Hi,

Yes, I figured it was something like that. But don’t you think that Ruby
should be able to figure that out?

Actually, Ruby tried to figure out what you meant (by looking
whitespace), but I guess yours were different.

How do you think Ruby should figure out, when both

a.foo * 1.1 => a.foo()*1.1
a.foo *1.1 => a.foo(*1.1)

are legal?

All I can say now is “use whitespace consistently (or symmetrically)”,
until someone come up with better idea.

						matz.
···

In message "Re: [BUG] “illegal radix 1"” on 03/04/11, Daniel Carrera dcarrera@math.umd.edu writes:

Your point about high-level languages is good, but this is the cost of
Ruby’s power. Most high-level languages are pretty simple and
gutless, making it easy to normalise the input.

Fortunately, as Matz said, the -w flag picks up things like this
easily. I use it as a habit.

The only time I really have trouble finding where a parse (or similar)
error occurs is when I’ve left out a closing bracket or something.

Gavin

···

On Friday, April 11, 2003, 5:26:48 PM, Daniel wrote:

“2”.to_i *1.1
ArgumentError: illegal radix 1
from (irb):2:in `to_i’
from (irb):2
“2”.to_i * 1.1
=> 2.2

“2”.to_i *1.1 is parsed as “2”.to_i(*1.1). Try -w if you have doubt.

Yes, I figured it was something like that. But don’t you think that Ruby
should be able to figure that out?
I don’t know. I don’t think I’ve seen this problem in other high-level
languages. I guess that this is part of how I would expect a high-level
language to “stay out of my way” and let me focus on the problem I am
actually trying to solve.

I guess that is reasonable, but why
does the error say 1 instead of 1.1?

Hal

···

----- Original Message -----
From: “Yukihiro Matsumoto” matz@ruby-lang.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, April 11, 2003 3:10 AM
Subject: Re: [BUG] “illegal radix 1”

How do you think Ruby should figure out, when both

a.foo * 1.1 => a.foo()*1.1
a.foo *1.1 => a.foo(*1.1)

are legal?

All I can say now is “use whitespace consistently (or symmetrically)”,
until someone come up with better idea.

Well, I would normally expect * to be parsed differently (different
precedence). In particular, all of these:

ab, a b, a *b, a * b

Would be parsed as ‘(a)*(b)’. And if I want ‘a(*b)’ then that is
precisely what I would type.

In nearly all cases, when I use * I mean multiplication. For me, the use
‘a(*b)’ is so uncommon, that when that’s what I want I write it explicitly
to avoid ambiguity.

I would set the default parsing to (foo)*(1.1) in all cases, and only use
‘foo(*1.1)’ when explicitly stated.

Perhaps there’s a good reason why all this is a bad idea. But this
behaviour just seems much more natural to me.

···

On Fri, Apr 11, 2003 at 05:10:03PM +0900, Yukihiro Matsumoto wrote:

How do you think Ruby should figure out, when both

a.foo * 1.1 => a.foo()*1.1
a.foo *1.1 => a.foo(*1.1)

are legal?


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

In nearly all cases, when I use * I mean multiplication.

Yes, but based on your .sig, I’m guessing you’re a heavy math-head. (I don’t
say that like its bad, mind you, I’m only a wannabe math-head.)

For me, the use
‘a(*b)’ is so uncommon, that when that’s what I want I write it explicitly
to avoid ambiguity.

I would set the default parsing to (foo)*(1.1) in all cases, and only use
‘foo(*1.1)’ when explicitly stated.

FWIW, I agree.

> In nearly all cases, when I use * I mean multiplication. For me, the use > 'a(*b)' is so uncommon, that when that's what I want I write it explicitly > to avoid ambiguity. > > I would set the default parsing to (foo)*(1.1) in all cases, and only use > 'foo(*1.1)' when explicitly stated.

For me it’s the other way around. I have yet to use any multiplication
in this object system, but I use *args quite a bit. Everything from
argument list forwarding to widget parameter passing:

o = Class.new_on(connection, :volume, arg0, …)

r = Row.new(1, 2, 3) # Row#new declares with *args

or

a = [1, 2, 3]

do stuff to a

r = Row.new *a

It all depends on context, and unfortunately there’s no way for ruby
to know the context. I believe it’s just the same thing as the "1+ 1"
problem. Besides, if your code looks like that, you really should make
it look nicer. :wink: :wink:

···

On Sat, 12 Apr 2003 04:13:52 +0900 Daniel Carrera dcarrera@math.umd.edu wrote:


Ryan Pavlik rpav@users.sf.net

“That’s the first pratical line of thinking to
come out of your word hole since we first met.” - 8BT

I guess that is reasonable, but why
does the error say 1 instead of 1.1?

ruby has converted 1.1 to an integer, this is valid

pigeon% ruby -e 'p "c".to_i(16)'
12
pigeon%

the argument given to String#to_i is the base to convert the string

Guy Decoux