Berger, Daniel
2/2/2006 3:39:00 PM
> -----Original Message-----
> From: Martin DeMello [mailto:martindemello@yahoo.com]
> Sent: Thursday, February 02, 2006 7:43 AM
> To: ruby-talk ML
> Subject: Re: ruby-dev summary 28206-28273
>
>
> Minero Aoki <aamine@loveruby.net> wrote:
> >
> > [ruby-dev:28217] ANDCALL operator
> >
> > Nobuyoshi Nakada suggested a new operator `&?' (this
> notation is temporary)
> > which evaluates left-hand-side expression, and if it is
> true then call
> > right-hand-side method. For example:
> >
> > if a[1] and a[1].strip.empty?
> > ||
> > if a[1] &? strip.empty?
> >
> > h["key"] and h["key"].dispatch
> > ||
> > h["key"] &? dispatch
> >
> > The motivation of this operator is to avoid duplication of
> > expression.
> >
> > Takaaki Tateishi proposed another idea, Object#nil? with block
> > (again, this name is temporary).
> >
> > a[1].nil? {|str| str.strip.empty? }
> > h["key"].nil? {|h| h.dispatch }
> >
> > This issue is still open.
Yuck. Looks like a hack from Perl6. Not Ruby-ish.
> Syntactically, a method might look better than an operator:
>
> a[1].if?.strip.empty?
> a[1].maybe.strip.empty?
> a[1].and.strip.empty?
>
> martin
Looks better syntactically, but still has problems as Austin pointed
out.
I'd sooner accept "iff" (if and only if):
iff h["key"].dispatch -> same as: h["key"].dispatch if h["key"]
But, the idea of adding new keywords doesn't thrill me and I worry that
it's too terse.
Regards,
Dan