News for hackers. Stuff that matters.
Re:Pyret Programming Language by satyanash on Sunday August 22, 2021 @03:17AM (#28263551)
The ruby comparison is unfair:

    o = Object.new
    def o.my_method(x)
      self.y + x
    end
    def o.y
      10
    end
    o.my_method(5) == 15 # true
    method_as_fun = o.my_method
    # Wrong number of arguments, 0 for 1
The last line is actually doing: method_as_fun = o.my_method()

Which should make the error message obvious. Ruby makes this syntax optional for readability purposes, which becomes obvious once you start going through real world ruby code.

Re:Pyret Programming Language by catwell on Sunday August 22, 2021 @04:59AM (#28263959)
Yes, that would be:

    method = o.method(:my_method)
    method.call(5)
    # or method[5], or method.(5)
If you really want a "function" that you can call with parens:

   Kernel.define_method(:method_as_fun, &method)
(Definitely don't do that last bit in a real project...)
Re:Pyret Programming Language by jonnytran on Sunday August 22, 2021 @02:07PM (#28267896)
And before someone criticizes Ruby for being inconsistent in how the method is called, Ruby isn't a callable oriented language [1]. The common case is calling methods, so the fact that you need to say `.call(5)` both makes it more consistent and makes real code more concise, especially when making DSLs where chaining is really useful.

1: https://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-ori...

Re:Pyret Programming Language by danwills on Sunday August 22, 2021 @04:35AM (#28263828)
I think if you put more newlines in your code example (at least two per code-line) it might come through the HN formatting thing better?
Re:Pyret Programming Language by lluu on Sunday August 22, 2021 @04:53AM (#28263915)
The way to do the last bit in Ruby is:

  method_as_fun = o.method(:my_method)
  method_as_fun.call(5) # 15