ruby-dev summary 27393-27541

A

Austin Ziegler

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.

Yes, but there may be cases where one has a number of operations that
one needs to make with a selector namespace. I think that the *option*
for "using jcode do...end" is a good thing.
 
B

Bill Kelly

From: "Ara.T.Howard said:
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.

There's only one reason I've been eagerly awaiting selector namespaces,
and it was that I thought it meant we would be able to, in our own
modules (or namespaces) be able to redefine core methods, and have
these changes be in effect only within our own namespace.

I was imagining something like:

namespace foo
require 'mathn' # without changing mathn source
p 5/9 # => 5/9
end

p 5/9 # => 0

I.e. by defining and working in a namespace, you'd be insulating
the rest of Ruby from changes made within that namespace,
particularly overriding core class' methods.


I guess with the proposed scheme, it would be,

require 'mathn' # presuming mathn changed to use namespaces

using mathn

p 5/9 # => 5/9

stopusing mathn

p 5/9 # => 0

???


Is it true that with the proposed approach, the source code of
mathn would have to be changed to make it define its methods
explicitly within a namespace? Is there no way to 'require'
a module into a namespace without having to change the module's
source code?


Regards,

Bill
 
M

Mauricio Fernández

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 :)

Wasn't Ruby Behaviors dynamically scoped though?
It seems Ruby's selector namespaces are more likely to be static.
 
M

Mauricio Fernández

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.

Yes, but there may be cases where one has a number of operations that
one needs to make with a selector namespace. I think that the *option*
for "using jcode do...end" is a good thing.

IIRC from the original thread (around [ruby-dev:27421]), a
using jcode
expression would activate the namespace until the end of some "syntactical
feature" (such as the end of the current method/class).
 
D

Dale Martenson

---- Original message from Bill Kelly on 11/2/2005 11:23 AM:
There's only one reason I've been eagerly awaiting selector namespaces,
and it was that I thought it meant we would be able to, in our own
modules (or namespaces) be able to redefine core methods, and have
these changes be in effect only within our own namespace.

I was imagining something like:

namespace foo
require 'mathn' # without changing mathn source
p 5/9 # => 5/9
end

p 5/9 # => 0

I.e. by defining and working in a namespace, you'd be insulating
the rest of Ruby from changes made within that namespace,
particularly overriding core class' methods.


I guess with the proposed scheme, it would be,

require 'mathn' # presuming mathn changed to use namespaces

using mathn

p 5/9 # => 5/9

stopusing mathn

p 5/9 # => 0

???


Is it true that with the proposed approach, the source code of
mathn would have to be changed to make it define its methods
explicitly within a namespace? Is there no way to 'require'
a module into a namespace without having to change the module's
source code?
I thought there would be specific uses:

1. Global namespace change to allow for transistion from one namespace
to another.

Example: (please note my alternative syntax)

require 'mathn'
namespace mathn, :begin
p 5/9 # => 5/9
namespace mathn, :end
p 5/9 # => 0

or

require 'mathn'
namespace mathn do
p 5/9 # => 5/9
end
p 5/9 # => 0

2. A notational convenience for class/module definition.

class Bubba
using home_security
def nickel_plated_45
end
end

Pardon my syntax. Just try out some different flavors.
 
D

David A. Black

--8323328-1082049744-1130959427=:7625
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1082049744-1130959427=:7625"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1082049744-1130959427=:7625
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

Wasn't Ruby Behaviors dynamically scoped though?
It seems Ruby's selector namespaces are more likely to be static.

That was one of the things on the list of unresolved questions in the
summary. I'm actually not entirely clear on what static would mean in
this context.


David

--=20
David A. Black
(e-mail address removed)
--8323328-1082049744-1130959427=:7625--
--8323328-1082049744-1130959427=:7625--
 
A

Ara.T.Howard

Is there no way to 'require' a module into a namespace without having to
change the module's source code?

something like this?

http://groups.google.com/group/comp...q=howard+trans+module&rnum=5#b39d5538b0f5218f


-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
===============================================================================
 
B

Bill Kelly

From: "Ara.T.Howard said:

Neat; but what I'm looking for may be just unreasonable. When I
require 'mathn', it does:

class Fixnum
alias / quo
end

class Bignum
alias / quo
end

I wanted to wrap that require in a namespace, so that its changes
to core classes would be isolated to that namespace.

. . But I don't mean to belabor the point - as it seems that
namespaces aren't going to "wrap" definitions automatically...


Regards,

Bill
 
K

Kev Jackson

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, ....
Isn't using the keyword from C# for declaring namespaces? Similar to
package com.myco.module.whatever that Java uses.

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.

Looking at the options so far, I really like

using jcode
str.chop
end

To me it looks much more ruby than

using jcode

...
...

...

str.chop

Kev
 
K

Kero

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.

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

+--- Kero ------------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://members.chello.nl/k.vangelder ---+
 
C

Christophe Grandsire

Selon Kero :
p "\244\242\244\244".chop using jcode

Nice one. But then I'd rather have my proposal of putting the namespace
after the method name adopted and just write:

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

I know: "boohoo! syntax!" But it's a syntax that's rather natural
considering the omnipresence of e-mail addresses nowadays, and it's not
as if Ruby doesn't use @ already, nor ever uses one symbol for two
different (but unambiguous) roles.
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

You need a straight mind to invent a twisted conlang.
 
D

daz

Kero said:
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.

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

But then how to express (as proposed):

p "\244\242\244\244".jcode$chop.kcode$change

Gets silly ?

p "\244\242\244\244".(chop using jcode).(change using kcode)
p "\244\242\244\244".chop.change using jcode, kcode # ??

Same problems with block level - identifies only one namespace
and no specific connection to any/all referenced methods within
that block.

I guess ruby-dev will have been through this process.

Check responses against this contrivance :-/

p "\244\242\244\244".jcode$chop.kcode$chop

Sometimes, a new language feature can be helped by new syntax.
When all single chr syntax has been used, two chrs are suggested.
One 2-chr combo is often as silly as the next.
'using' is a 5-chr combo ...
'each_with_index' is a ... hang on ... anyway, they're readable
and have no 'sharp & pointy' arrows.

I'm so sorry, I seem to have 'gone off on one'.


daz
 
D

Dave Burt

Christophe said:
p "\244\242\244\244".chop@jcode

I know: "boohoo! syntax!" But it's a syntax that's rather natural
considering the omnipresence of e-mail addresses nowadays, and it's not as
if Ruby doesn't use @ already, nor ever uses one symbol for two different
(but unambiguous) roles.

It's too close to:
p "\244\242\244\244".chop @jcode

That's an ArgumentError, but it would be a valid call to chomp, for
instance.

FWIW, I think I like the block-style idea, but rescue-ish is good, too.

def foo # or any block-starting thing
# global namespace
using my_namespace
# specific namespace
end
# global namespace again

and you could also allow a trailing using to apply the namespace to the
whole expression:

"foo".reverse.capitalize using my_wacky_string_namespace

Cheers,
Dave
 
T

Trans

In the past I always thought of ':' (boy that comes up a lot ;-)

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

But I'm wondering if two colons could work,

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

because a namespace is much like a module. Also maybe

p "\244\242\244\244".(jcode)chop

By the way Facets can already do some stuff like this via:

module JCode
def chop
...
end
end

class String
include JCode
end

"\244\242\244\244".as(JCode).chop

Yep. If you guessed Functor, you are right.

T.
 
E

Eero Saynatkari

Trans said:
In the past I always thought of ':' (boy that comes up a lot ;-)

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

Yes, this is usually the syntax I prefer to illustrate selector namespaces.
They would also (visually) benefit from being constants (i.e. uppercase
rather than lowercase).

However, it seems that the name 'selector namespace' is a bit inaccurate
for the current implementation as it concentrates much more on the 'namespace'
than the 'selector' which is unfortunate. I would much rather see this:

module NS
def foo
puts 'NS' + @foo
end
end

class Foo
def initialize
@foo = 'foo'
end

def foo
puts 'Foo' + @foo
end
end

f = Foo.new
puts f.foo # Foofoo
puts f.NS:foo # NSfoo


Here there is no concrete namespace but rather a namespace is dynamically
created to facilitate selecting the implementation. Again, this is perhaps more
AOP-like than some would prefer and perhaps this is missing some benefits of
the other approach.

E.face[:cheek] = :tongue

p "\244\242\244\244".JCode-chop

p "\244\242\244\244".chop~JCode

p "\244\242\244\244".jcode->chop

p "\244\242\244\244".JCode#chop

But I'm wondering if two colons could work,

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

because a namespace is much like a module. Also maybe

p "\244\242\244\244".(jcode)chop

By the way Facets can already do some stuff like this via:

module JCode
def chop
...
end
end

class String
include JCode
end

"\244\242\244\244".as(JCode).chop

Yep. If you guessed Functor, you are right.

T.

E
 
K

Kero

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.

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

But then how to express (as proposed):

p "\244\242\244\244".jcode$chop.kcode$change

Gets silly ?

A bit silly, yes

p "\244\242\244\244".chop.change using jcode using kcode

Works as long as there is no conflict. The problem of conflicting
namespaces was mentioned in this thread; I ask, do we care?

class X
include A
include B
end

may conflict as well, but we accept that methods from B override methods
from A (in the same way jcode would override kcode in my example above).

If there is such a conflict, you would/should/could do

chopped = "\244\242\244\244".chop using jcode
p chopped.change using kcode

..

obj.xtract.manipulate.serialize using FunnyNamespace

if you need three namespaces here, did you do a proper design job?
(the answer can be Yes, but I suppose it's mostly No; if it is Yes, I
certainly hope the namespaces have different purposes)

The same story (both overriding and the amount of namespaces needed)
holds for

begin
using OneNamespace
using LogElsewhere
using AnotherNamespace {
...code...
}
end

whether using is in block style or not.

Bye,
Kero.

+--- Kero ------------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://members.chello.nl/k.vangelder ---+
 
K

Kero

It's too close to:
p "\244\242\244\244".chop @jcode

That's an ArgumentError, but it would be a valid call to chomp, for
instance.

holds as well for

jcode $chop
jcode :chop
chop :jcode

and probably some other ideas in this thread.

I recall someone asking whther namespaces would be 'different' from
methods, i.e. if there is also a *method* jcode in the example above,
the space is really wreaking havoc.

Bye,
Kero.

+--- Kero ------------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://members.chello.nl/k.vangelder ---+
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top