Forum: Ruby-core [ruby-trunk - Feature #6672][Open] Calling #() without dot before braces

Posted by prijutme4ty (Ilya Vorontsov) (Guest)
on 2012-06-30 00:19
(Received via mailing list)
Issue #6672 has been reported by prijutme4ty (Ilya Vorontsov).

----------------------------------------
Feature #6672: Calling #() without dot before braces
https://bugs.ruby-lang.org/issues/6672

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


It looks odd to call Proc/Method `pr` using `pr.(*args)` or `pr[*args]` 
syntax. Why not to use pr(*args) syntax? In such a case methods(procs) 
would become nearer to first-class object and calls are more 
standardized such that there's much less difference between method call 
and call of #call method

So I suggest syntax `x.(*args,&block)` alias to `x(*args,&block)`
It will make it possible to transparently redefine any method in a scope 
like this:
class String
  def my_meth(direction)
    index = method :rindex  if direction == 'RtoL'
#   ... lots of code that uses #index method
  end

  def my_second_meth
    upcase = method :downcase  # we decided to try what if we change all 
upcases to downcases in this method and added such a line
# lots of code using upcase() method
    upcase()  # it's sad that it's impossible not to use brackets at 
all, but this'd be ambiguous
  end
end

Also I wrote about syntax like :meth.(*args) which creates a 
proxy-object having to_proc method - so that it's possible to write 
[1,2,3].map &:to_s.(2)  --  now no dot in such syntax

Also it'd be possible to implement some object with syntax like 
`obj(args1)(args2)` - obj has method #call that returns object that also 
has method #call and they are both called.
It can be in such a way: method(:index)('z')

One problem is that it can behave differently from current behavior in 
case that method have the same name as a local-variable. Now it works in 
such a way:
p='var';
print p #=> 'var'  ## works as local variable
p('hi') #=> 'hi'   ## works as method call

I don't know if it's a spec, I suppose that one mustn't use both 
variable and method at the same place. So even it's a spec it can be 
revised in future versions of ruby so that new behaviour would be like 
that:
p='var';
print p #=> 'var'  ## works as local variable
p('hi') #=> undefined method `call` for 'var':String
Posted by Nobuyoshi Nakada (nobu)
on 2012-06-30 01:04
(Received via mailing list)
Issue #6672 has been updated by nobu (Nobuyoshi Nakada).

Description updated

FYI, this is a feature which had been implemented once and reverted in 
the past.

> I don't know if it's a spec, I suppose that one mustn't use both variable and 
method at the same place. So even it's a spec it can be revised in future versions 
of ruby so that new behaviour would be like that:

Yes, it's a spec, and there was so many code depending this, more than 
expected before the try.
----------------------------------------
Feature #6672: Calling #() without dot before braces
https://bugs.ruby-lang.org/issues/6672#change-27578

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
It looks odd to call Proc/Method `(({pr}))` using `(({pr.(*args)}))` or 
`(({pr[*args]}))` syntax. Why not to use (({pr(*args)})) syntax? In such 
a case methods(procs) would become nearer to first-class object and 
calls are more standardized such that there's much less difference 
between method call and call of (({#call})) method

So I suggest syntax `(({x.(*args,&block)}))` alias to 
`(({x(*args,&block)}))`
It will make it possible to transparently redefine any method in a scope 
like this:
  class String
    def my_meth(direction)
      index = method :rindex  if direction == 'RtoL'
  #   ... lots of code that uses #index method
    end

    def my_second_meth
      upcase = method :downcase  # we decided to try what if we change 
all upcases to downcases in this method and added such a line
  # lots of code using upcase() method
      upcase()  # it's sad that it's impossible not to use brackets at 
all, but this'd be ambiguous
    end
  end

Also I wrote about syntax like (({:meth.(*args)})) which creates a 
proxy-object having to_proc method - so that it's possible to write 
(({[1,2,3].map &:to_s.(2)}))  --  now no dot in such syntax

Also it'd be possible to implement some object with syntax like 
`(({obj(args1)(args2)}))` - obj has method (({#call})) that returns 
object that also has method (({#call})) and they are both called.
It can be in such a way: (({method(:index)('z')}))

One problem is that it can behave differently from current behavior in 
case that method have the same name as a local-variable. Now it works in 
such a way:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> 'hi'   ## works as method call

I don't know if it's a spec, I suppose that one mustn't use both 
variable and method at the same place. So even it's a spec it can be 
revised in future versions of ruby so that new behaviour would be like 
that:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> undefined method `call` for 'var':String
=end
Posted by prijutme4ty (Ilya Vorontsov) (Guest)
on 2012-06-30 02:10
(Received via mailing list)
Issue #6672 has been updated by prijutme4ty (Ilya Vorontsov).


nobu (Nobuyoshi Nakada) wrote:
> FYI, this is a feature which had been implemented once and reverted in the past.
>
> > I don't know if it's a spec, I suppose that one mustn't use both variable and 
method at the same place. So even it's a spec it can be revised in future versions 
of ruby so that new behaviour would be like that:
>
> Yes, it's a spec, and there was so many code depending this, more than expected 
before the try.

Sadly. It looks that code basing on such a spec isn't written in a good 
manner =\
----------------------------------------
Feature #6672: Calling #() without dot before braces
https://bugs.ruby-lang.org/issues/6672#change-27580

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
It looks odd to call Proc/Method `(({pr}))` using `(({pr.(*args)}))` or 
`(({pr[*args]}))` syntax. Why not to use (({pr(*args)})) syntax? In such 
a case methods(procs) would become nearer to first-class object and 
calls are more standardized such that there's much less difference 
between method call and call of (({#call})) method

So I suggest syntax `(({x.(*args,&block)}))` alias to 
`(({x(*args,&block)}))`
It will make it possible to transparently redefine any method in a scope 
like this:
  class String
    def my_meth(direction)
      index = method :rindex  if direction == 'RtoL'
  #   ... lots of code that uses #index method
    end

    def my_second_meth
      upcase = method :downcase  # we decided to try what if we change 
all upcases to downcases in this method and added such a line
  # lots of code using upcase() method
      upcase()  # it's sad that it's impossible not to use brackets at 
all, but this'd be ambiguous
    end
  end

Also I wrote about syntax like (({:meth.(*args)})) which creates a 
proxy-object having to_proc method - so that it's possible to write 
(({[1,2,3].map &:to_s.(2)}))  --  now no dot in such syntax

Also it'd be possible to implement some object with syntax like 
`(({obj(args1)(args2)}))` - obj has method (({#call})) that returns 
object that also has method (({#call})) and they are both called.
It can be in such a way: (({method(:index)('z')}))

One problem is that it can behave differently from current behavior in 
case that method have the same name as a local-variable. Now it works in 
such a way:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> 'hi'   ## works as method call

I don't know if it's a spec, I suppose that one mustn't use both 
variable and method at the same place. So even it's a spec it can be 
revised in future versions of ruby so that new behaviour would be like 
that:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> undefined method `call` for 'var':String
=end
Posted by boris_stitnicky (Boris Stitnicky) (Guest)
on 2012-11-18 04:37
(Received via mailing list)
Issue #6672 has been updated by boris_stitnicky (Boris Stitnicky).


In that case this issue should be closed. (I also think this feature is 
too much sugar.)
----------------------------------------
Feature #6672: Calling #() without dot before braces
https://bugs.ruby-lang.org/issues/6672#change-33044

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=begin
It looks odd to call Proc/Method `(({pr}))` using `(({pr.(*args)}))` or 
`(({pr[*args]}))` syntax. Why not to use (({pr(*args)})) syntax? In such 
a case methods(procs) would become nearer to first-class object and 
calls are more standardized such that there's much less difference 
between method call and call of (({#call})) method

So I suggest syntax `(({x.(*args,&block)}))` alias to 
`(({x(*args,&block)}))`
It will make it possible to transparently redefine any method in a scope 
like this:
  class String
    def my_meth(direction)
      index = method :rindex  if direction == 'RtoL'
  #   ... lots of code that uses #index method
    end

    def my_second_meth
      upcase = method :downcase  # we decided to try what if we change 
all upcases to downcases in this method and added such a line
  # lots of code using upcase() method
      upcase()  # it's sad that it's impossible not to use brackets at 
all, but this'd be ambiguous
    end
  end

Also I wrote about syntax like (({:meth.(*args)})) which creates a 
proxy-object having to_proc method - so that it's possible to write 
(({[1,2,3].map &:to_s.(2)}))  --  now no dot in such syntax

Also it'd be possible to implement some object with syntax like 
`(({obj(args1)(args2)}))` - obj has method (({#call})) that returns 
object that also has method (({#call})) and they are both called.
It can be in such a way: (({method(:index)('z')}))

One problem is that it can behave differently from current behavior in 
case that method have the same name as a local-variable. Now it works in 
such a way:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> 'hi'   ## works as method call

I don't know if it's a spec, I suppose that one mustn't use both 
variable and method at the same place. So even it's a spec it can be 
revised in future versions of ruby so that new behaviour would be like 
that:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> undefined method `call` for 'var':String
=end
Posted by matz (Yukihiro Matsumoto) (Guest)
on 2012-11-18 16:26
(Received via mailing list)
Issue #6672 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected


----------------------------------------
Feature #6672: Calling #() without dot before braces
https://bugs.ruby-lang.org/issues/6672#change-33059

Author: prijutme4ty (Ilya Vorontsov)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:


=begin
It looks odd to call Proc/Method `(({pr}))` using `(({pr.(*args)}))` or 
`(({pr[*args]}))` syntax. Why not to use (({pr(*args)})) syntax? In such 
a case methods(procs) would become nearer to first-class object and 
calls are more standardized such that there's much less difference 
between method call and call of (({#call})) method

So I suggest syntax `(({x.(*args,&block)}))` alias to 
`(({x(*args,&block)}))`
It will make it possible to transparently redefine any method in a scope 
like this:
  class String
    def my_meth(direction)
      index = method :rindex  if direction == 'RtoL'
  #   ... lots of code that uses #index method
    end

    def my_second_meth
      upcase = method :downcase  # we decided to try what if we change 
all upcases to downcases in this method and added such a line
  # lots of code using upcase() method
      upcase()  # it's sad that it's impossible not to use brackets at 
all, but this'd be ambiguous
    end
  end

Also I wrote about syntax like (({:meth.(*args)})) which creates a 
proxy-object having to_proc method - so that it's possible to write 
(({[1,2,3].map &:to_s.(2)}))  --  now no dot in such syntax

Also it'd be possible to implement some object with syntax like 
`(({obj(args1)(args2)}))` - obj has method (({#call})) that returns 
object that also has method (({#call})) and they are both called.
It can be in such a way: (({method(:index)('z')}))

One problem is that it can behave differently from current behavior in 
case that method have the same name as a local-variable. Now it works in 
such a way:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> 'hi'   ## works as method call

I don't know if it's a spec, I suppose that one mustn't use both 
variable and method at the same place. So even it's a spec it can be 
revised in future versions of ruby so that new behaviour would be like 
that:
  p='var';
  print p #=> 'var'  ## works as local variable
  p('hi') #=> undefined method `call` for 'var':String
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.