4 ms·
You 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! Th
by empthought 4y ago
You 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.