ruby-dev summary 27393-27541

M

Minero Aoki

Hi all,

This is a summary of ruby-dev #27393-27541.

[ruby-dev:27406] Ripper.new("").parse blocks

Akira Tanaka reported that Ripper.new("").parse blocks. This is because:

1. Ripper.new checks #gets method for the argument.
2. rb_respond_to() returns true for private methods.
3. Ripper.new calls String#gets, which is equivalent to private
method Kernel#gets.
4. Kernel#gets reads data from $stdin, it blocks.

To solve this problem, nobu posted a patch to change rb_respond_to()
behavior, and the patch is incorporated. Now rb_respond_to() returns
true only for public methods.

[ruby-dev:27417] selector namespace

Shugo Maeda proposed a new language feature, "selector namespace".
Matz also noted this topic in his key note at Ruby Conference 2005.

Selector namespace is a namespace of selector (method name). This
function is useful to replace methods temporarily. For example,
current jcode.rb replaces String#chop itself, which effects globally.
But with selector namespace, it effects only in "jcode" namespace.

class String
def jcode$chop # define #chop method in jcode namespace
...
end
end

# "\244\242\244\244" is Japanese characters 'A'+'I' in EUC-JP
p "\244\242\244\244".chop # "\244\242\244" # wrong result
p "\244\242\244\244".jcode$chop # "\244\242" # right result

You can omit namespace specifier ("jcode$") by using "using" syntax:

class String
def jcode$chop() ... end
end

using jcode
p "\244\242\244\244".chop # "\244\242" # right result

There are still many arguments, for example:

* whether "using" effects statically or dynamically
* '$' is ugly
* scope of "using" (file level / module level / method level)
* whether spaces are allowed around '$'

[ruby-dev:27424] value of BEGIN block

Nobuyoshi Nakada posted a patch to get a value of BEGIN block, like
following code:

val = BEGIN { 2 ** 345 }

You can utilise this function like `once' method provided by Eiffel
programming language:

# p is executed 5000 times but 2**345 is calculated only once
5000.times do
p(BEGIN { 2 ** 345 })
end

This issue is still open.

[ruby-dev:27449] --without-foo

Usaku Nakamura posted a patch to add new configure options to select
compiling extension libraries. For example, you can disable Win32API
library and io/wait library by following options:

$ ./configure --without-Win32API --with-io/wait=no

This patch is incorporated to CVS trunk HEAD.

[ruby-dev:27470] def Foo::Bar.baz

Shyouhei URABE claimed that "def Foo::Bar.baz" should be valid:

~ % ruby -ce 'def Foo::Bar.baz() end'
-e:1: syntax error, unexpected '.', expecting ';' or '\n'
def Foo::Bar.baz() end
^
-e:1: syntax error, unexpected kEND, expecting $end

Matz rejected this claim because we cannot add this syntax without
any (yacc's) conflict.

[ruby-dev:27548] ruby 1.8.4 preview 1 released

Matz released ruby 1.8.4 preview 1.

ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.4-preview1.tar.gz
MD5 sum: cfb6e4c53369c016ebb4061c240c493d


-- Minero Aoki
ruby-dev summary index: http://i.loveruby.net/en/ruby-dev-summary.html
 
C

Christophe Grandsire

Selon Minero Aoki said:
There are still many arguments, for example:

* whether "using" effects statically or dynamically
* '$' is ugly
* scope of "using" (file level / module level / method level)
* whether spaces are allowed around '$'

For the "'$' is ugly" argument, what about a syntax putting the namespace
*after* the method name, and with an '@' in between (i.e. chop@jcode here=
)? It
fits quite well with the "at" meaning that '@' has taken from things like
e-mail And namespaces are different enough from classes and modules that =
I
don't see why they should be put in front of method calls like those. And
reading it becomes quite easy and fitting:

class String
def chop@jcode # "define chop at jcode"
...
end
end

I'd think spaces should be disallowed around the '@' in that case, but it=
's just
an aesthetic opinion.

Also, how one would access the "namespaced" method using something like s=
end,
without using "using" first? I mean, "send(jcode$:chop)" just looks wrong=
, and
"send:)jcode$chop)" doesn't look right either. Using my syntax,
"send:)chop@jcode)" is a bit nicer (at least ":chop" stays together witho=
ut
clashes of symbols), but I'm still not sure I like it myself. Maybe a "se=
nd"
with an optional second parameter for the namespace...

By the way, are namespaces in their own namespace? (pardon the repetition=
)

Anyway, just my two cents about this interesting feature.
[ruby-dev:27470] def Foo::Bar.baz

Shyouhei URABE claimed that "def Foo::Bar.baz" should be valid:

~ % ruby -ce 'def Foo::Bar.baz() end'
-e:1: syntax error, unexpected '.', expecting ';' or '\n'
def Foo::Bar.baz() end
^
-e:1: syntax error, unexpected kEND, expecting $end

Matz rejected this claim because we cannot add this syntax without
any (yacc's) conflict.

First the block default arguments, now this... It's indeed time to get ri=
d of
yacc or patch it... Don't look at me! I can't do C :(( ...
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
C

Christophe Grandsire

Selon Christophe Grandsire said:
class String
def chop@jcode # "define chop at jcode"
...
end
end

I know it's not nice to reply to one's own mail, but looking at it again =
I
realised that putting the namespace after the method allows one to use
namespaces for class and singleton methods without syntax problems. On ca=
n
simply write:

def obj.method@namespace
...
end

without having to wonder whether the namespace should come before or afte=
r the
object name (yes, I know using "class <<obj; def method@namespace ... end=
; end"
solves the problem also, but it's nicer if the namespace syntax can easil=
y
support *all* existing syntaxes :) ).

Now the only problem would be how difficult it would be to parse my propo=
sal...
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
D

David A. Black

Hi --

class String
def jcode$chop # define #chop method in jcode namespace
...
end
end

# "\244\242\244\244" is Japanese characters 'A'+'I' in EUC-JP
p "\244\242\244\244".chop # "\244\242\244" # wrong result
p "\244\242\244\244".jcode$chop # "\244\242" # right result

You can omit namespace specifier ("jcode$") by using "using" syntax:

class String
def jcode$chop() ... end
end

using jcode
p "\244\242\244\244".chop # "\244\242" # right result

There are still many arguments, for example:

* whether "using" effects statically or dynamically
* '$' is ugly
* scope of "using" (file level / module level / method level)

How about block level?

using jcode do
p "\244\242\244\244".chop
end


David
 
C

Christophe Grandsire

Selon "David A. Black said:
How about block level?

using jcode do
p "\244\242\244\244".chop
end

Nice idea. Maybe block level when one gives a block, and module or method=
level
when one doesn't (not unlike how "private" and "public" behave, depending=
on
whether they receive a parameter or not).
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
N

nobuyoshi nakada

Hi,

At Wed, 2 Nov 2005 22:02:05 +0900,
Christophe Grandsire wrote in [ruby-talk:163734]:
I'd think spaces should be disallowed around the '@' in that case, but it's just
an aesthetic opinion.

Not just aesthets. The difference has a big impact to its
implementation.
Also, how one would access the "namespaced" method using something like send,
without using "using" first? I mean, "send(jcode$:chop)" just looks wrong, and
"send:)jcode$chop)" doesn't look right either. Using my syntax,
"send:)chop@jcode)" is a bit nicer (at least ":chop" stays together without
clashes of symbols), but I'm still not sure I like it myself. Maybe a "send"
with an optional second parameter for the namespace...

I thought only second, :jcode$chop. That is, it is just an name.
By the way, are namespaces in their own namespace? (pardon the repetition)

I don't think they can be nested.
 
N

nobuyoshi nakada

HI,

At Wed, 2 Nov 2005 22:17:45 +0900,
David A. Black wrote in [ruby-talk:163736]:
How about block level?

using jcode do
p "\244\242\244\244".chop
end

I had asked Shugo the question in [ruby-dev:27419], and his
answer is that he prefers one-line construct, since he doesn't
like to deepen indent level more.
 
A

Ara.T.Howard

[ruby-dev:27417] selector namespace

Shugo Maeda proposed a new language feature, "selector namespace". Matz
also noted this topic in his key note at Ruby Conference 2005.

Selector namespace is a namespace of selector (method name). This function
is useful to replace methods temporarily. For example, current jcode.rb
replaces String#chop itself, which effects globally. But with selector
namespace, it effects only in "jcode" namespace.

class String
def jcode$chop # define #chop method in jcode namespace
...
end
end

# "\244\242\244\244" is Japanese characters 'A'+'I' in EUC-JP
p "\244\242\244\244".chop # "\244\242\244" # wrong result
p "\244\242\244\244".jcode$chop # "\244\242" # right result

You can omit namespace specifier ("jcode$") by using "using" syntax:

class String
def jcode$chop() ... end
end

using jcode
p "\244\242\244\244".chop # "\244\242" # right result

i don't see why the above cannot be

class String
def jcode::chop
end
end

p "\244\242\244\244".jcode::chop

using String::jcode (i assume that was what was meant - surely String's
jcode is not exported to the top level or we'd have
many clashing namespaces!)

'::' is non-ambiguous in all these situations. this syntax also suggests

class String
namespace jcode
def chop
end
namespace util
...
end
namespace const
...
end
end
end

in otherwords, namespaces may be declared in a nested way.

now i suppose yacc will be the problem... ;-(


-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================
 
D

David A. Black

Hi --

Nice idea. Maybe block level when one gives a block, and module or method level
when one doesn't (not unlike how "private" and "public" behave, depending on
whether they receive a parameter or not).

That's similar to what I did in Ruby Behaviors, but with an "off"
switch for the non-block version:

# Block
b.adopt do
...
end

# No block
b.adopt
...
b.desist

(where b is a Behavior object)

Of course, Ruby Behaviors had some issues, especially thread safety --
which is what got the discussion going about selector namespaces at
RubyConf 2001 :)


David
 
A

Ara.T.Howard

I don't think they can be nested.

then they would not be useful. surely everyone will want to nest a 'util',
'const', or other common name in their classes. if they cannot be nested too
many name classes would occur - something i would expect namespaces to solve.


-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================
 
A

Ara.T.Howard

How about block level?

using jcode do
p "\244\242\244\244".chop
end

I had asked Shugo the question in [ruby-dev:27419], and his answer is that
he prefers one-line construct, since he doesn't like to deepen indent level
more.

but then how to i __stop__ using a namespace?

using jcode

....

stopusing jcode

??

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================
 
D

David A. Black

Hi --

How about block level?

using jcode do
p "\244\242\244\244".chop
end

I had asked Shugo the question in [ruby-dev:27419], and his answer is that
he prefers one-line construct, since he doesn't like to deepen indent level
more.

but then how to i __stop__ using a namespace?

using jcode

....

stopusing jcode

See my previous post, with an example from Ruby Behaviors.


David
 
C

Christophe Grandsire

Selon nobuyoshi nakada said:
I thought only second, :jcode$chop. That is, it is just an name.

It still looks strange to me. I'd really rather have namespaces after rat=
her
than before the method name. Especially if using '@' (pronounced 'at') as=
I
did. It just feels easier to read (especially since you still keep the ob=
ject
and its method next to each other, with just a period in between, unlike =
the
current syntax which puts a possibly arbitrary name between the object an=
d the
method it receives). In other words, I find:

string.chop@namespace(args)

easier to read than:

string.namespace$chop(args)

Strangely enough I don't have that much problems putting the namespace be=
tween
the method name and its arguments :) .
tion)

I don't think they can be nested.

I wasn't clear, sorry (the attraction of the pun was just too much for me=
to
resist :/ ). I meant to ask whether namespace names would be clashing wit=
h
method names (or variable names?) or if they were completely separate (an=
d thus
would allow me to give to a namespace the same name as an existing method=
for
instance). Also, can one start a namespace name with a capital letter?
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
D

daz

Minero said:

Hi Aoki-san - Thank you.

[ruby-dev:27417] selector namespace

Shugo Maeda proposed a new language feature, "selector namespace".
Matz also noted this topic in his key note at Ruby Conference 2005.

class String
def jcode$chop # define #chop method in jcode namespace
...
end
end

[...]


def jcode:>chop

a = ns:>Foo::Bar.baz


Really easy to type :)

* whether spaces are allowed around [':>']

Follow rules of quad :):)

class A; class B; C5 = 5; end; end

A::B::C5
#-> 5

A::B :: C5
#-> C:/TEMP/rb8125.TMP:4: uninitialized constant C5 (NameError)


daz
 
C

Christophe Grandsire

Selon "Ara.T.Howard said:
but then how to i __stop__ using a namespace?

using jcode

....

stopusing jcode

putting_away jcode

;)

Seriously, it's a good question. One-liner constructs may be nice in some=
cases,
but there's a reason why a construction like File.open { |file| ... } is =
so
great: people just *forget* to close things when they don't use them anym=
ore.
And frankly, there's nothing wrong with adding a level of indentation,
especially when one is dealing with *namespaces*, which are just a differ=
ent
kind of named scope.
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
A

Ara.T.Howard

See my previous post, with an example from Ruby Behaviors.

sure. but afaikt there is no jcode __object__ in the initial post to call
methods on.

surely the bare token 'jcode' cannot be it, otherwise

using jcode

jcode = 42

would have disaterous effects. hopefully it would, in fact, be

String::jcode

so we might also have

Iconv::jcode

and, if this 'jcode' thing is an object why not create it directly with

namespace jcode
...
end

rather than implicitly using

def jcode::method
end

i'm unclear how this whole construct is more useful that using modules as
namespaces, which can be nested and manipulated like all other module/classes.

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================
 
D

David A. Black

Hi --

sure. but afaikt there is no jcode __object__ in the initial post to call
methods on.

surely the bare token 'jcode' cannot be it, otherwise

using jcode

jcode = 42

would have disaterous effects. hopefully it would, in fact, be

I guess part of my problem here is that I think "using" is the wrong
word, unless it's before a block. Otherwise it feels like it's just
dangling:

Using this namespace, ....

as opposed to:

Use this namespace!

or

Select this namespace!

But generally, I think having both a block and a non-block way to do
it, rather than just one or the other, makes the most sense.


David
 
A

Ara.T.Howard

But generally, I think having both a block and a non-block way to do
it, rather than just one or the other, makes the most sense.

completely agree.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================
 
D

Daniel Berger

Minero said:
Hi all,

This is a summary of ruby-dev #27393-27541.

[ruby-dev:27417] selector namespace

Shugo Maeda proposed a new language feature, "selector namespace".
Matz also noted this topic in his key note at Ruby Conference 2005.

Selector namespace is a namespace of selector (method name). This
function is useful to replace methods temporarily. For example,
current jcode.rb replaces String#chop itself, which effects globally.
But with selector namespace, it effects only in "jcode" namespace.

class String
def jcode$chop # define #chop method in jcode namespace
...
end
end

# "\244\242\244\244" is Japanese characters 'A'+'I' in EUC-JP
p "\244\242\244\244".chop # "\244\242\244" # wrong result
p "\244\242\244\244".jcode$chop # "\244\242" # right result

You can omit namespace specifier ("jcode$") by using "using" syntax:

class String
def jcode$chop() ... end
end

using jcode
p "\244\242\244\244".chop # "\244\242" # right result

There are still many arguments, for example:

* whether "using" effects statically or dynamically
* '$' is ugly
* scope of "using" (file level / module level / method level)
* whether spaces are allowed around '$'

For those interested, Sydney will accomplish selector namespaces via Behaviors.
The exact syntax isn't settled yet, but you can look at
http://www.livejournal.com/users/djberg96/50830.html for some ideas (and follow
the link at the bottom to see the actual code).

I definitely prefer a block level approach. I think Evan is leaning towards
the "object.method using :namespace" syntax.

Regards,

Dan
 
T

Trans

I agree with Ara. What's being presented here looks like it may be s
simple name "hack", i.e.

define_method( "jcode$chop" ) { ... }

'using' just auto prefixes all method calls. This isn't true namespace
selectors, is it?

What we need is as Ara suggests and my expiremention confirms, are
module/module-like constructs.

class String

namespace JCode ; end

def JCode.chop
...
end

end

In fact modules themselves can be used here with the concept of
self-shimmying, which has been disccussed a good deal on suby mailing
list. (I'll resue $ here for demonstration purposes):

class X

module M
def x
self
end
end

def show_em_how_you_shimmy
M$x
end

end

X.new.show_em_how_you_shimmy #=> #<X ...>

Which is the simplified essence of namespace selector.

T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top