Bugs

Hi!

I’ve noticed some bugs in ruby (I expect another results)

I tested it under Ruby172-4.exe (downloaded from thePragmaticProgrammer
page), winME

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!

Another one:

def a
b=2
end

a()
puts b

prints 2

And the last (for today)
one,two=‘asdf’.split(‘-’) # >> [‘asdf’]
a1,a2=‘’.split(‘-’) # >>

one=‘asdf’ two=nil
a1=nil a2=nil

I don’t see the point why split returns an empty array, when it has a
VALID, but empty input string. It should return an array returning one
empty element, so [‘’].
Opinions?

Gergo
±[Kontra, Gergely @ Budapest University of Technology and Economics]-+

    Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |

URL: turul.eet.bme.hu/~kgergely Mobile: (+36 20) 356 9656 |
±------“Olyan langesz vagyok, hogy poroltoval kellene jarnom!”-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

Hi!

I’ve noticed some bugs in ruby (I expect another results)

I tested it under Ruby172-4.exe (downloaded from thePragmaticProgrammer
page), winME

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!
Correct.

Another one:

def a
b=2
end

a()
puts b

prints 2
Also correct.
Remember that variables in Ruby has no ‘local’ context.

···

On Thu, Oct 03, 2002 at 01:46:37AM +0900, Kontra, Gergely wrote:


/ Alexander Bokovoy

Q: How do you save a drowning lawyer?
A: Throw him a rock.

Hi,

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!

Yes, using block argument equals to assignment to it.

Another one:

def a
b=2
end

a()
puts b

prints 2

Really? I got this error:

-:6: undefined local variable or method `b’ for #Object:0x402de95c (NameError)

I don’t see the point why split returns an empty array, when it has a
VALID, but empty input string. It should return an array returning one
empty element, so [‘’].

‘’.split(‘-’, -1) # => [‘’]

···

At Thu, 3 Oct 2002 01:46:37 +0900, Kontra, Gergely kgergely@mlabdial.hit.bme.hu wrote:


Nobu Nakada

Alexander Bokovoy wrote:

Another one:

def a
b=2
end

a()
puts b

prints 2

Also correct.
Remember that variables in Ruby has no ‘local’ context.

Ruby most certainly does have a ‘local’ context. The variable ‘b’ should
be local to the method ‘a’.

When I tested this, I got an error similar to that of Nobu Nakada’s:
-:6: undefined local variable or method ‘b’ for #Object:0x2a79360
(NameError)

Using ‘ruby 1.7.2 (2002-07-02) [i386-mswin32]’ on Windows 2000.

Cheers,

bs.

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!

Yes, using block argument equals to assignment to it.

But shouldn’t it be local to the block? It may cause nice errors…
If it is available outside the block, it is a Bad Idea™.

‘’.split(‘-’, -1) # => [‘’]

Ok, but is it a trailing null? (doc is not very correct (ok, rather old
doc 0.3))
In my opinion split should return at least ONE real string.

Gergo
±[Kontra, Gergely @ Budapest University of Technology and Economics]-+

    Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |

URL: turul.eet.bme.hu/~kgergely Mobile: (+36 20) 356 9656 |
±------“Olyan langesz vagyok, hogy poroltoval kellene jarnom!”-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!

Yes, using block argument equals to assignment to it.

But shouldn’t it be local to the block? It may cause nice errors…
If it is available outside the block, it is a Bad Idea™.

This is an issue discussed previously on this list as well as feature
enhancements to Ruby in future versions if I am not mistaken. In the above
code k is defined outside the code block and that is why it’s assignment
within the code block is retained outside of it.

Yes, forget about my response on it, too much work per day :frowning:

···

On Thu, Oct 03, 2002 at 02:36:59AM +0900, Ben Schumacher wrote:

Alexander Bokovoy wrote:

Another one:

def a
b=2
end

a()
puts b

prints 2

Also correct.
Remember that variables in Ruby has no ‘local’ context.

Ruby most certainly does have a ‘local’ context. The variable ‘b’ should
be local to the method ‘a’.

/ Alexander Bokovoy


McDonald’s – Because you’re worth it.

k=‘Hello’
[1,2,3].map {|k| k}
puts k
It prints 3 under ruby1!
Yes, using block argument equals to assignment to it.
But shouldn’t it be local to the block? It may cause nice errors…
If it is available outside the block, it is a Bad Idea™.
This is an issue discussed previously on this list as well as feature
enhancements to Ruby in future versions if I am not mistaken. In the above
code k is defined outside the code block and that is why it’s assignment
within the code block is retained outside of it.

So it won’t change in the future?

Gergo

±[Kontra, Gergely @ Budapest University of Technology and Economics]-+

    Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |

URL: turul.eet.bme.hu/~kgergely Mobile: (+36 20) 356 9656 |
±------“Olyan langesz vagyok, hogy poroltoval kellene jarnom!”-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

Unfortunately, I haven’t been using Ruby that long but again noticed the
topic discussed. I am sure it is preferable to have a ‘local’ context as
would be expected but it can affect older code. I have confidence that the
individuals running the Ruby show will come up with something to satisfy us
all : )

···

At 03:34 AM 10/3/2002 +0900, you wrote:

k=‘Hello’
[1,2,3].map {|k| k}
puts k
It prints 3 under ruby1!
Yes, using block argument equals to assignment to it.
But shouldn’t it be local to the block? It may cause nice errors…
If it is available outside the block, it is a Bad Idea™.
This is an issue discussed previously on this list as well as feature
enhancements to Ruby in future versions if I am not mistaken. In the above
code k is defined outside the code block and that is why it’s assignment
within the code block is retained outside of it.

So it won’t change in the future?

This is a “Ruby Gotcha”. IF you declare a variable before the
block, it uses that one. If you don’t, it creates its own, but its
scope IS the block.

I find this… odd, and I don’t like it, but that’s the way it is.

···

— “Kontra, Gergely” kgergely@mlabdial.hit.bme.hu wrote:

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!

Yes, using block argument equals to assignment to it.

But shouldn’t it be local to the block? It may cause nice errors…
If it is available outside the block, it is a Bad Idea™.

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

:slight_smile: This has been discussed in probably hundreds
of posts in the last 2-3 years. The range of
opinions is something like this:
a. It’s a bug
b. It’s a feature
c. It’s an oddity
d. It’s too late to fix it easily
e. Various combinations of the above

Go do a search for “block-local”… that should
turn up lots of insomnia-curing material.

Hal

···

----- Original Message -----
From: “Kontra, Gergely” kgergely@mlabdial.hit.bme.hu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, October 02, 2002 1:07 PM
Subject: Re: bugs

k=‘Hello’
[1,2,3].map {|k| k}
puts k

It prints 3 under ruby1!

Yes, using block argument equals to assignment to it.

But shouldn’t it be local to the block? It may cause nice errors…
If it is available outside the block, it is a Bad Idea™.

Hi Michael,

You can browse the just-started list at
http://www.glue.umd.edu/~billtj/ruby.html” (I will change it to HTML
format based on an input from someone); this is item 3) in the list.

Hopefully you will get fewer Ruby gotcha in the future.

Regards,

Bill

···

=========================================================================
Michael Campbell michael_s_campbell@yahoo.com wrote:

This is a “Ruby Gotcha”. IF you declare a variable before the
block, it uses that one. If you don’t, it creates its own, but its
scope IS the block.

I find this… odd, and I don’t like it, but that’s the way it is.

Hi,

···

In message “Re: bugs” on 02/10/03, “Kontra, Gergely” kgergely@mlabdial.hit.bme.hu writes:

So it won’t change in the future?

I’d like to “fix”. But the point is “how” I fix. I don’t know yet.

						matz.

I have confidence that the
individuals running the Ruby show will come up with something to satisfy us
all : )

I think that’s statistically impossible. ; )

Just ask “Is X/Y/Z a feature or a bug?” and observe the ensuing discussion.

~ B

···


_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
Bruce Williams http://www.codedbliss.com
iusris/#ruby-lang bruce@codedbliss.com
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/

Hi Matz,

I guess if you are going to use “@__xxx” as class private variables, then
probably it is consistent to use “__xxx” as block private
(local) variables.

Regards,

Bill

···

========================================================================
Yukihiro Matsumoto matz@ruby-lang.org wrote:

I’d like to “fix”. But the point is “how” I fix. I don’t know yet.

  					matz.

There was a poll on rubygarden.org, but the results were, ummm, unclear.
Wouldn’t each of the proposed modifications fix it? Then shouldn’t we
try to figure out what is the best one now instead of later? The
sooner we think about it, the better, IMHO.

As for me, I voted for |external;local|

···

On Thu, Oct 03, 2002 at 01:39:46PM +0900, Yukihiro Matsumoto wrote:

Hi,

In message “Re: bugs” > on 02/10/03, “Kontra, Gergely” kgergely@mlabdial.hit.bme.hu writes:

So it won’t change in the future?

I’d like to “fix”. But the point is “how” I fix. I don’t know yet.


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Turns out that grep returns error code 1 when there are no matches.
I KNEW that. Why did it take me half an hour?
– Seen on #Debian

I have confidence that the individuals running the Ruby show will
come up with something to satisfy us all : )
I think that’s statistically impossible. ; )

Possible solutions:

  1. All the parameters of the block are local to the block.
    Well, this way programs written in past won’t work.
    However you can pass values outside the block.
  2. Ability to define block vars local
    How to define them local?
    Extra typing for future programs.

So either old programs won’t work without modification,or new programs
need extra typing to avoid a probable bug. People will forget these
extra typings and create program bugs.

What about a version-marking system to provide compatibility?
Perl and some others have such a feature. You specify the version you
wrote your script for.
Next release will mark some old features depricated, and the version
after the next version will refuse to work?

So I think versioning maybe an acceptable choice (need 1 row extra
typing at the beginning of the program, or at the command line an extra
switch)

Gergo

±[Kontra, Gergely @ Budapest University of Technology and Economics]-+

    Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |

URL: turul.eet.bme.hu/~kgergely Mobile: (+36 20) 356 9656 |
±------“Olyan langesz vagyok, hogy poroltoval kellene jarnom!”-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

Gasp! So many underscores! So ugly!

Gavin

···

----- Original Message -----
From: “William Djaja Tjokroaminata” billtj@y.glue.umd.edu

Hi Matz,

I guess if you are going to use “@__xxx” as class private variables, then
probably it is consistent to use “__xxx” as block private
(local) variables.

Regards,

Bill

Hi Mauricio,

Isnt’t that using the syntax below contrary to “the ruby way” that we
should be able to create a variable at any time, anywhere?

Regards,

Bill

···

=======================================================================
Mauricio Fern?ndez batsman.geo@yahoo.com wrote:

As for me, I voted for |external;local|

Not quite:

a = [1, 2, 3]
b = “I’ll change”
c = “I’m static”
a.each do |b|
# whatever
# can use other vars any way I want
end

here b = 3

a.each do |;c|
#whatever
#can use other vars any way I want
end

c still the same

Now I see this syntax (or my understanding of it) is broken as you
cannot specify the order in which your vars are assigned…

Maybe
a.each do |:a,b,:c,d|

a and c local

b and d “external” (outer scope)

end

It is better to mark local vars as this way all the existing code works
unmodified. I’ve used ‘:’ cause I cannot think of any other semantics
for it in that position.

You see, it’s still “the Ruby way” as it’s just like before, only with
additional scope markers.

If we want to discriminate between variable usages, it’s either this or “my”…

···

On Thu, Oct 03, 2002 at 10:05:37PM +0900, William Djaja Tjokroaminata wrote:

As for me, I voted for |external;local|
Hi Mauricio,

Isnt’t that using the syntax below contrary to “the ruby way” that we
should be able to create a variable at any time, anywhere?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux: Where Don’t We Want To Go Today?
– Submitted by Pancrazio De Mauro, paraphrasing some well-known sales talk