Ruby-dev summary 18111-18212

Hello,

This is a summary of ruby-dev ML in these days.

---- ruby-dev #18111-18212 (2002-08-31 … 2002-09-6) ----

[ruby-dev:18185] autoload patch for ruby-1.7

Yoshinori K. Okuji first posted a patch which enables the autoload facility
to work with non-toplevel constants. Nobuyoshi Nakada posted a patch which
realize simpler implementation than Okuji’s one. Matz wrote “Now how should
we carry it out?”.

[ruby-dev:18114] Object#become

Koji Arai asked what is a difference between “replace” and “become” of String,
Array and Hash. Matz answered that there is semantically no difference between
them at present. But it is not decided how they come to be.

[ruby-dev:18186] [req] Marshal

We can’t marshal an object which has singleton methods. This leads a conclusion
that we can’t marshal an object extending a module, so this constraint seems
not to be reasonable.
Keiju Ishitsuka requested if we can get rid of the constraint. Matz took it as
an actual idea, and worth considering.

[ruby-dev:18197] VALUEs in yacc stack

Minero Aoki made the GC to work at parsing time, if yacc uses alloca() for
allocating its semantic stack.

···


Takaaki Tateishi ttate@kt.jaist.ac.jp

Interesting question.

Someone on irc pointed out that there is an Object#become in CVS now.
When I look at the source, though, it doesn’t look like it does anything
except raise an exception if obj is frozen or if obj and orig are not
the same type. Then it returns the original object.

I also notice that Object#become gets called by copy_object, right after
setting the flags in the destination object and right before copying the
instance variables.

Questions:

  1. Is this how Object#become is supposed to behave, or is this a
    work-in-progress?

  2. What logic is there in using Object#become to implement copying of
    the object? I was under the impression that Object#become was
    supposed to “swap” the objects, which would make it hard to use for
    copying.

  3. Why doesn’t Object#become copy the instance variables, instead of
    having copy_object copy them?

Paul

···

On Mon, Sep 09, 2002 at 09:05:49PM +0900, Takaaki Tateishi wrote:

[ruby-dev:18114] Object#become

Koji Arai asked what is a difference between “replace” and “become”
of String, Array and Hash. Matz answered that there is semantically
no difference between them at present. But it is not decided how
they come to be.

Hi,

I'm not the right person to answer, but
···

In article 20020909101507.P20993@atdesk.com, Paul Brannan wrote:

Questions:

  1. Is this how Object#become is supposed to behave, or is this a
    work-in-progress?

  2. What logic is there in using Object#become to implement copying of
    the object? I was under the impression that Object#become was
    supposed to “swap” the objects, which would make it hard to use for
    copying.

  3. Why doesn’t Object#become copy the instance variables, instead of
    having copy_object copy them?

please, have look at how is #clone, #dup done in CVS version.

	Michal


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos Czech Technical University, Prague
E-mail:m.rokos@sh.cvut.cz ICQ:36118339 Jabber:majkl@jabber.cz
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Hi,

···

In message “Re: ruby-dev summary 18111-18212” on 02/09/09, Paul Brannan pbrannan@atdesk.com writes:

Someone on irc pointed out that there is an Object#become in CVS now.
When I look at the source, though, it doesn’t look like it does anything
except raise an exception if obj is frozen or if obj and orig are not
the same type. Then it returns the original object.

Because “become” is a method to copy internal state that Ruby
interpreter does not know, the default “become” does nothing but
freeze check.

						matz.

Interesting. Is this what “become” does in Smalltalk?

Also, in Ruby 1.6 I might write:

class Foo
def clone
puts “clone!”
return Foo.new
end
end

f = Foo.new
p f.dup

I’m implementing only “clone” because dup in 1.6 is implemented in
terms of clone. So the output I get from 1.6 is:

clone!
#Foo:0x402929dc

but Ruby 1.7 gives me:

#Foo:0x401da550

if I want to implement dup/clone for an object in an extension, what is
the correct way to do this so that it will work with both 1.6 and 1.7?

Paul

···

On Tue, Sep 10, 2002 at 09:17:39AM +0900, Yukihiro Matsumoto wrote:

Hi,

In message “Re: ruby-dev summary 18111-18212” > on 02/09/09, Paul Brannan pbrannan@atdesk.com writes:

Someone on irc pointed out that there is an Object#become in CVS now.
When I look at the source, though, it doesn’t look like it does anything
except raise an exception if obj is frozen or if obj and orig are not
the same type. Then it returns the original object.

Because “become” is a method to copy internal state that Ruby
interpreter does not know, the default “become” does nothing but
freeze check.

Hi,

Interesting. Is this what “become” does in Smalltalk?

It’s not. I’ve heard Smalltalk “become” is too dangerous.

perhaps I have to choose another name. Ideas?

if I want to implement dup/clone for an object in an extension, what is
the correct way to do this so that it will work with both 1.6 and 1.7?

define both clone and become, e.g.

def become(orig)
# copy internal state
end

def clone
c = super
c.become(self)
end

in 1.7 become is called twice, but it should be OK.

						matz.
···

In message “Re: ruby-dev summary 18111-18212” on 02/09/10, Paul Brannan pbrannan@atdesk.com writes:

Interesting. Is this what “become” does in Smalltalk?

It’s not. I’ve heard Smalltalk “become” is too dangerous.

perhaps I have to choose another name. Ideas?

I think a lot of people will be surprised by this, so I agree it should
probably be given a different name.

Some ideas for a name: copy, copy_from, copy_state, xerox, replicate.

What problems/limitations were there with the old style of only
implementing clone in the derived class? While become() could be used
to copy one object into another, it copies only internal state, so I
can’t really see myself calling it directly.

if I want to implement dup/clone for an object in an extension, what is
the correct way to do this so that it will work with both 1.6 and 1.7?

define both clone and become, e.g.

def become(orig)
# copy internal state
end

def clone
c = super
c.become(self)
end

in 1.7 become is called twice, but it should be OK.

Interesting; I think that should work. It’s a little inconvenient,
though, and it would be nice if the interpreter gave me a warning, so
if I define only clone() on Ruby 1.7 the code won’t silently break.

Paulk

···

On Wed, Sep 11, 2002 at 12:22:58AM +0900, Yukihiro Matsumoto wrote:

Some ideas for a name: copy, copy_from, copy_state, xerox,
replicate.

“Xerox” is almost certainly trademarked, copywritten (copyrighted?),
patented, or whichever of those applies to names. GPL’d, maybe. =)

···

=====

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

Yahoo IM: michael_s_campbell


Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

Which is why I used a lowercase ‘x’ :slight_smile:

Paul

···

On Wed, Sep 11, 2002 at 02:35:16AM +0900, Michael Campbell wrote:

Some ideas for a name: copy, copy_from, copy_state, xerox,
replicate.

“Xerox” is almost certainly trademarked, copywritten (copyrighted?),
patented, or whichever of those applies to names. GPL’d, maybe. =)