[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Syntax sugar: method[](...) => method(...

Yukihiro Matsumoto

7/10/2007 3:55:00 AM

Hi,

In message "Re: Syntax sugar: method[](...) => method(...)"
on Tue, 10 Jul 2007 04:08:26 +0900, Gary Wright <gwtmp01@mac.com> writes:

|This would probably be a headache from a parsing perspective but what
|about something like:
|
| obj.login@[date]

Why we need syntax sugar when we can just call

obj.login(date)

? Maybe you need

obj.login(date)=whatever

this could be a new RCR.

matz.


3 Answers

Nobuyoshi Nakada

7/10/2007 4:21:00 AM

0

Hi,

At Tue, 10 Jul 2007 12:54:58 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:258520]:
> ? Maybe you need
>
> obj.login(date)=whatever
>
> this could be a new RCR.

I'd tried it once but abandoned. I don't think it impossible,
but it must be a really non-trivial change of parse.y.

--
Nobu Nakada

Florian Groß

7/10/2007 1:16:00 PM

0

On Jul 10, 5:54 am, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:
> ? Maybe you need
>
> obj.login(date)=whatever
>
> this could be a new RCR.

Or a really old one: http://oldrcrs.rubypal.com/rc...

... :)


Gary Wright

7/10/2007 6:29:00 PM

0


On Jul 9, 2007, at 11:54 PM, Yukihiro Matsumoto wrote:
> In message "Re: Syntax sugar: method[](...) => method(...)"
> on Tue, 10 Jul 2007 04:08:26 +0900, Gary Wright
> <gwtmp01@mac.com> writes:
>
> |This would probably be a headache from a parsing perspective but what
> |about something like:
> |
> | obj.login@[date]
>
> Why we need syntax sugar when we can just call
>
> obj.login(date)

I think that there is a significant semantic difference (to the
programmer)
between brackets and parenthesis.

foo(bar) # foo is interpreted as a verb
foo[bar] # foo is interpreted as a noun (a collection of
some sort)

The language rules also force different semantics on those two
expressions.
In the first, 'foo' must be a method associated with self and so the
method
has semantics defined by the definition of 'foo' but it isn't clear
from the
syntax that some sort of indexing is being attempted.

In the second expression, there may be one or two method calls
depending on whether
'foo' is a local variable or not. In either case, the interpretation
of [bar] is not
done by a method associated with self but instead by a method
associated with the
value of 'foo', which might be the result of a method call.

The benefit of some alternate indexing syntax is that the name of the
collection and
the implementation of indexing on the collection can be localized to
a single
method associated with self rather than delegating the indexing logic
to an
intermediate object (the value of 'foo').

This would also probably reek havoc on parse.y but what about:

foo@(bar)
foo@(bar) = x

This builds upon Ruby's use of foo! and foo? as having distinct
meanings.


Gary Wright