3 ms·
Ruby doesn't have first-class methods, either. Python has both first-class methods and first-class functions. > In computer science, a programming language is
by empthought 4y ago
Ruby 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?
- empthought 4y agoThis is such an asinine argument. Function pointers and passing an environment struct in C let you do everything an OO language does. What are you unable to do in C that you can do in Ruby? You can implement a type system in Scheme if you really want to, what can you do in Haskell that you can’t do in Scheme? Just admit you are wrong, bud. It’s not as hard as you’re making it out to be. Strachey’s definition is quite clear and Ruby doesn’t have first-class functions nor first-class methods. It’s a language flaw just like Python’s lambda is a language flaw.
- djur 4y agoI'm not sure how clear Strachey's definition can be, considering he never provided one. But his description of ALGOL procedures as second-class mentions that they can "never be represented by a variable or expression": https://en.wikipedia.org/wiki/First-class_citizen#History https://en.wikipedia.org/wiki/First-class_citizen#History In Ruby you can assign a function to a variable, pass it to a function as a parameter, return it as the result of a function, and test two function objects for equality. Ruby has first-class functions. If it didn't, you would easily be able to provide an example of a program using first-class functions that cannot be represented in Ruby.