5 ms·
I didn't know Ruby didn't have first-class functions but that's already a massive no for me. You don't need to convince me regarding Python though - it's too co
by arcturus17 4y ago
I didn't know Ruby didn't have first-class functions but that's already a massive no for me. You don't need to convince me regarding Python though - it's too convenient to pass up. And despite its shortcomings it's certainly not a language devoid of elegance like some in this thread are painting... Like the old adage goes, there's the languages nobody uses, and there's the languages people talk shit about. Or in simpler terms, as seen in this thread: "everything I don't use is utter shit".
- djur 4y agoI have no idea what they mean by Ruby not having first-class functions. Of course it does. It's a fundamental feature of the language.
- empthought 4y agoNo it does not. Ruby has first-class procs. They are not the same thing. It's a fundamental flaw of the language. It's in the Wikipedia page. https://en.wikipedia.org/wiki/First-class_function https://en.wikipedia.org/wiki/First-class_function "The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed. It must first be retrieved into a Method or Proc object to be used as first-class data. The syntax for calling such a function object differs from calling regular methods." Why do people like you insist on talking about things you don't actually know about?
- djur 4y agoThe Wikipedia article is wrong. A proc is a function. The misunderstanding here is confusing methods with functions. "def foo" defines a method, not a function. That same article claims that Java has first class functions on the basis of anonymous inner classes, that C# has them because of lambda expressions, etc. OCaml has different syntax for functions and methods. Does that mean it doesn't have first-class functions? You should really consider whether this is an important enough topic to be worth personally insulting people over.
- empthought 4y agoRuby doesn't have first-class methods, either. Python has both first-class methods and first-class functions. > In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.[1] OCaml has first-class functions, the names can be passed around as parameters and returned as values. Ruby functions and methods cannot; only Proc objects and Method objects proxying for them can be. You should really consider whether pointing out your incorrectness constitutes an insult and why you think this is so.
- djur 4y agoEverything is an object in Ruby. Proc objects and Method objects _are_ functions. The same is true in Python -- functions are instances of the 'function' class. What's the difference between a proc and a function? Nothing. "[P]eople like you insist on talking about things you don't actually know about" is insulting language. Consider discussing this with some people you know in real life to see what they think.
- empthought 4y agoYou can’t use a Proc or Method value directly to call a method with the Ruby method invocation syntax! In Python and JavaScript and Scheme and OCaml you can! This is the whole idea behind “first-class.” Whether “everything is an object” or not is irrelevant.
- djur 4y agoThere is nothing about first-class functions that requires function call syntax to be the same as method invocation syntax. OCaml, Objective-C, and Smalltalk all have different syntax for method invocation and function calls. To make it concrete: what are you unable to do in Ruby that you're able to do in the languages that you claim do have first-class functions?
- dragonwriter 4y ago> Ruby has first-class procs. Procs are functions (at least, they are functionally equivalent to Python functions—as pure OO languages, in both Ruby and Python first-class callable entities are richer than classic functions, even when counting closures as a kind functions and not a separate thing that includes a function, because they can carry metadata besides the environment of a closure.) > It's in the Wikipedia page. The Wikipedia page is wrong in that conclusion. > The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed A method is a very different thing than a function. But, on a deeper level, I think it is also a mistake to call the thing it is referring the identifier for the method, its just syntax sugar for a symbol passed to a #send call, which, if send isn't overwritten on the sender (which it probably shouldn’t be, overriding send is a good way to cause chaos) will result in the method being called, unless some other method has priority. > The syntax for calling such a function object differs from calling regular methods The syntax is different only inna waybthat reflects thebdifferent behavior. Calling #call on a Proc or Method object (again, assuming a sane world where the object’s send method isn’t overidden) does dynamic method lookup on the :call name in the Method or Proc, and its syntax is exactly normal method-call syntax for that behavior (unless you use the shortcut syntax of “.()” for “.call()”, but that's just syntax sugar). Using normal method call syntax does dynamic lookup on the method name provided in the call on the receiver object identified in the call. That is, Ruby methods are first class, but what it is a convenient shortcut to think of as “method call syntax” in Ruby is not really method call syntax, it is syntax for a message send that will (by overridable default) result in calling a method with that name if it exists in the ancestor chain of classes for the object, so it is inaccurate to view the “method call” syntax excluding any parameters as “the identifier for the method”.
- djur 4y ago> its just syntax sugar for a symbol passed to a #send call This isn't the case. If you override `send` it only affects direct usage of `send`. You can't override method dispatch. You can in some other OO languages but not Ruby. Agreed otherwise. `x.foo` in Python and `x.method(:foo)` in Ruby do the exact same thing -- return a bound method object that can be called. These are both "proxies" in a sense but they're also first-class functions in all meaningful senses.
- arcturus17 4y agoNoted. I've read the rest of the conversation and it's very interesting.