[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Alternate notation for eigenclass

Trans

3/13/2006 5:36:00 PM

Rather then using a specific method for accessing the
singleton/eigennclass, could we just use an alternate to dot-notation.
I.e. Instead of 'x.eigenclass.foo' either 'x:foo' or 'x!foo', or
somthing like that.

I haven't given a great deal of thought, and don't really have time to,
but it popped into my mind today, so I decided to just throw it out
there.

T.

27 Answers

Austin Ziegler

3/13/2006 6:25:00 PM

0

On 3/13/06, Trans <transfire@gmail.com> wrote:> Rather then using a specific method for accessing the> singleton/eigennclass, could we just use an alternate to dot-notation.> I.e. Instead of 'x.eigenclass.foo' either 'x:foo' or 'x!foo', or> somthing like that.>> I haven't given a great deal of thought, and don't really have time to,> but it popped into my mind today, so I decided to just throw it out> there.As long as we don't call it "eigenclass". To pick on your specificproposal, isn't x:foo going to be used for selector namespaces? x!foolooks odd, to me. I'm not opposed to the idea in general, but thenumber of sigils in use in Ruby is already high, and I think I'dprefer a method overall.-austin--Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca

Sam Smoot

3/14/2006 4:28:00 AM

0

I don't like it. Why do we need special notation? x.eigenclass.foo is
instantly recognizeable. x!foo is nice and short, but it also adds to
the syntax of the language, raising the bar for newcomers.

I don't suppose that's necessarily a reason to dismiss it, but I would
err on the side of simplicity unless there's a really compelling reason
not to. I favor the "and-call" operator because it's a shortcut to a
really common pattern. I'm not seeing that you need to access the
eigenclass often enough to justify new syntax specifically for it
though.

Johan Veenstra

3/14/2006 8:11:00 AM

0

On 3/14/06, ssmoot@gmail.com <ssmoot@gmail.com> wrote:
>
> I don't like it. Why do we need special notation? x.eigenclass.foo is
> instantly recognizeable. x!foo is nice and short, but it also adds to
> the syntax of the language, raising the bar for newcomers.
>
> I don't suppose that's necessarily a reason to dismiss it, but I would
> err on the side of simplicity unless there's a really compelling reason
> not to. I favor the "and-call" operator because it's a shortcut to a
> really common pattern. I'm not seeing that you need to access the
> eigenclass often enough to justify new syntax specifically for it
> though.


Maybe 'myclass' or 'selfclass' instead of 'eigenclass'

dblack

3/14/2006 2:27:00 PM

0

Trans

3/14/2006 2:35:00 PM

0

> Or singleton_class, which is what it's called :-)

Really?

x = "A"
=> "A"
irb(main):002:0> x.singleton_class
NoMethodError: undefined method `singleton_class' for "A":String
from (irb):2

Yet...

irb(main):003:0> require 'singleton'
=> true
irb(main):004:0> class A
irb(main):005:1> include Singleton
irb(main):006:1> end
=> A

T.

dblack

3/14/2006 2:41:00 PM

0

Gary Wright

3/14/2006 3:20:00 PM

0


On Mar 13, 2006, at 12:38 PM, Trans wrote:
> Rather then using a specific method for accessing the
> singleton/eigennclass, could we just use an alternate to dot-notation.
> I.e. Instead of 'x.eigenclass.foo' either 'x:foo' or 'x!foo', or
> somthing like that.

When I first encountered singleton class notation in Ruby:

class <<obj; end

I thought of '<<' in this situation as a prefix operator on the object.
I suppose you hack the parser to understand that but I'm guessing it
would really tangle up the grammar. In any case, the parser doesn't
treat
the text after the 'class' keyword as an expression. You can't
substitute
'<<obj' for an expression that evaluates to an eigenclass. I always
thought
that was strange. Why doesn't the parser just look for an expression
that
evaluates to a class object? The superclass can be specified by an
expression,
why can't the 'regular' class be handled in the same way?

In any case, I think that '<<obj' is seems out of place relative
to the rest of Ruby's syntax.

I'd prefer a method to access the singleton class object:

obj.singleton_class

is OK but I tend to like more terse names:

obj.sclass

If we had this, I would expect:

class obj.sclass
end

to do the obvious thing and open up obj's singleton class.

Gary Wright



dblack

3/14/2006 3:44:00 PM

0

Gary Wright

3/14/2006 9:42:00 PM

0


On Mar 14, 2006, at 10:44 AM, dblack@wobblini.net wrote:
> I'm certainly a Kernel#s[ingleton_]class advocate, but I don't think
> it's obvious that this change in the behavior of the class keyword
> would follow, since:
>
> class some_class_in_a_variable
>
> doesn't work. I don't know the reasoning behind it.

Yes. My comment regarding expressions after the 'class' keyword
was a more general comment on the syntax/semantics of a class/end block
than anything specific to singleton class notation.

I just find the semantics/syntax of the 'class' keyword a bit strange.

Here is another example:

(class A; self; end)

is not a valid expression in a method definition but:

(class << obj; self; end)

is just fine. And as I said earlier, Ruby is quite happy to have an
expression as the superclass such as:

class ProxyArray < DelgateClass(Array)
end

I would think that

class expression
#code
end

would be analogous to

expression.class_eval { # code }

Gary Wright


Trans

3/14/2006 9:58:00 PM

0

That's an interesting view point Gary. Hadn't thouhgt of it that way. I
agree that '<<' always stuck out like a sore thumb to me too. One would
think it is an operator. But it's more like 'class<<' is a keyword.
Odd.

I like how your idea lends itself to using variables for classes in the
syntax, which David points out doesn't work presently --but I don't see
why it couldn't.

OTOH, using the YAS (Yet Another Sigil) idea I suggested,

class obj!
end

Is bit interesting too. But maybe everyone's right about introducing
YAS.

Speaking of "sigil" that gives me a notion.

obj.sigclass

or just

obj.sig

Where 'sig' of course means 'special interest group'. Hey, it's got the
right meaning. :-)

T.