Ruby-dev summary 18811-18923

Hello,

I present you a ruby-dev summary in these days.

[ruby-dev:18818] CFD: adding “condition” and so on for tracing events

Hiroshi Nakamura suggested that the following events should be
notified to the tracer, which is set by set_trace_func.

- condition
  is notified at conditions.

- load-call
  is notified immediately before loading a file.

- load-return
  is notified immediately after loading a file.

- rescue
  is notified at rescue clauses.

Matz rejected the suggestion since they will make ruby slower.

[ruby-dev:18861] class variables

Matz proposed the better specification of class variable as follows.
He welcomes advice.

(1) In a toplevel layer of a class, uninitialized class variables
is forbidden to be substituted in a method.
He thinks that we had better initialize them like constants.

(2) In a declaration of a singleton class, initializing class variables
are forbidden.
It is because class variables belong to the most inner class/module
which is not singleton.

(3) Substituting class variables outside of method definitions give a
warning. This is an early detection of the error like constants.

(4) The scope of class variables is restricted only within the class/module.
All the subclasses can not access to those class variables.

[ruby-dev:18887] String#substr?

Takaaki Tateishi proposed a method for checking if a sub-string is exactly
same as other sub-string without creating a new string object. The method
suppresses the excessive cost of creating new strings.
Matz approved the idea, however rejected its method name ‘substr?’.

[ruby-dev:18896] spec. of format “%.nx”

Kazuhisa Yanagawa asked a question about the specification of the method
’format’, since the result of “%.3x”%-10 is “…f6” whereas its precision
is 3. The specification will be changed as follows.

"%.4x"%-10 #=> fff6
"%.3x"%-10 #=> ff6
"%.2x"%-10 #=> f6
"%.1x"%-10 #=> f6
···


Takaaki Tateishi ttate@kt.jaist.ac.jp

What’s the difference between this and String#include? ?

martin

···

Takaaki Tateishi ttate@kt.jaist.ac.jp wrote:

[ruby-dev:18887] String#substr?

Takaaki Tateishi proposed a method for checking if a sub-string is exactly
same as other sub-string without creating a new string object. The method
suppresses the excessive cost of creating new strings.
Matz approved the idea, however rejected its method name ‘substr?’.

Matz proposed the better specification of class variable as follows.
He welcomes advice.

(3) Substituting class variables outside of method definitions give a
warning. This is an early detection of the error like constants.

What do you mean by “substituting”?

(4) The scope of class variables is restricted only within the class/module.
All the subclasses can not access to those class variables.

Does this mean that class variables are no longer accessible to derived
classes? Won’t this break code?

Paul

···

On Mon, Nov 25, 2002 at 09:10:32PM +0900, Takaaki Tateishi wrote:

At Mon, 25 Nov 2002 21:43:28 +0900,

[ruby-dev:18887] String#substr?
Takaaki Tateishi proposed a method for checking if a sub-string is exactly
same as other sub-string without creating a new string object. The method
suppresses the excessive cost of creating new strings.
Matz approved the idea, however rejected its method name ‘substr?’.

What’s the difference between this and String#include? ?

I proposed a method like str1.include?(str2,beg,n), which means that
str1[beg,n] is equal to str2[0,n].
If we write “str1[beg,n] == str2[0,n]”, we extract sub-strings and
new objects are created. I think this brings much cost when we want to
repeat to compare two sub-strings whereas we don’t need new sub-strings.

Here is a sample implementation in ruby.

class String
def substr?(str, offset=nil, len=nil)
offset ||= 0
len ||= str.length
for i in 0…(len-1)
if( self[i+offset] != str[i] )
return false
end
end
return true
end
end

···


Takaaki Tateishi ttate@kt.jaist.ac.jp

I agree with you, Paul. I think this is fundamentally similar to my
previous proposal to make the scope of instance variables to be restricted
only within the class/module.

It is funny that in my simulator prototype while in derived classes I in
general do not access the parent’s instance variables directly, I do
access the parent’s class variables all the time. So it will definitely
break my codes… (ah…, really time to rewrite the whole thing in pure
C…)

Regards,

Bill

···

Paul Brannan pbrannan@atdesk.com wrote:

On Mon, Nov 25, 2002 at 09:10:32PM +0900, Takaaki Tateishi wrote:

(4) The scope of class variables is restricted only within the class/module.
All the subclasses can not access to those class variables.

Does this mean that class variables are no longer accessible to derived
classes? Won’t this break code?

Paul

At Mon, 25 Nov 2002 23:36:04 +0900,

(3) Substituting class variables outside of method definitions give a
warning. This is an early detection of the error like constants.

What do you mean by “substituting”?

I means a substitution “@@var = val”.

···


Takaaki Tateishi ttate@kt.jaist.ac.jp

Does this mean that the following will generate a warning:

class Foo
@@foo = 1
@@foo = 2
end

Will there be a way to suppress this warning (e.g. with constants I can
remove the constant before the second assignment)?

Paul

···

On Tue, Nov 26, 2002 at 01:44:34AM +0900, Takaaki Tateishi wrote:

At Mon, 25 Nov 2002 23:36:04 +0900,

(3) Substituting class variables outside of method definitions give a
warning. This is an early detection of the error like constants.

What do you mean by “substituting”?

I means a substitution “@@var = val”.

Ah, okay, I see. I can think of places this would have been useful -
have any other names been proposed? How about String#at?(beg, n, str)?

martin

···

Takaaki Tateishi ttate@kt.jaist.ac.jp wrote:

I proposed a method like str1.include?(str2,beg,n), which means that
str1[beg,n] is equal to str2[0,n].
If we write “str1[beg,n] == str2[0,n]”, we extract sub-strings and
new objects are created. I think this brings much cost when we want to
repeat to compare two sub-strings whereas we don’t need new sub-strings.

Takaaki Tateishi ttate@kt.jaist.ac.jp writes:

At Mon, 25 Nov 2002 21:43:28 +0900,

What’s the difference between this and String#include? ?

I proposed a method like str1.include?(str2,beg,n), which means that
str1[beg,n] is equal to str2[0,n].
If we write “str1[beg,n] == str2[0,n]”, we extract sub-strings and
new objects are created. I think this brings much cost when we want to
repeat to compare two sub-strings whereas we don’t need new sub-strings.

Here is a sample implementation in ruby.

class String
def substr?(str, offset=nil, len=nil)
offset ||= 0
len ||= str.length
for i in 0…(len-1)
if( self[i+offset] != str[i] )
return false
end
end
return true
end
end

I do not think this is necessarily a good idea, because indexing on a
string is not necessarily an O(1) operation. It can be O(N) when the
character encoding is UTF8 or similar, since character N does not
start at byte N.

Hi,

I means a substitution “@@var = val”.

Does this mean that the following will generate a warning:

class Foo
@@foo = 1
@@foo = 2
end

Yes.

Will there be a way to suppress this warning (e.g. with constants I can
remove the constant before the second assignment)?

remove_class_variable may help.

						matz.
···

In message “Re: ruby-dev summary 18811-18923” on 02/11/26, Paul Brannan pbrannan@atdesk.com writes:

I proposed a method like str1.include?(str2,beg,n), which means that
str1[beg,n] is equal to str2[0,n].
If we write “str1[beg,n] == str2[0,n]”, we extract sub-strings and
new objects are created. I think this brings much cost when we want to
repeat to compare two sub-strings whereas we don’t need new sub-strings.

Ah, okay, I see. I can think of places this would have been useful -
have any other names been proposed? How about String#at?(beg, n, str)?

martin

I propose String#matches?(beg, n, str)

Gavin

···

From: “Martin DeMello” martindemello@yahoo.com

Takaaki Tateishi ttate@kt.jaist.ac.jp wrote: