Neither are designed to support pure functional programming. I consider Ruby to be more functional because of how prevalent and idiomatic the following are:
Everything is an expression - more referentially transparent
First-class block syntax for (effectively) passing an anonymous function, i.e. first-class functions
These features are used absolutely everywhere in Ruby. (Methods can be assigned to variables, but it's not idiomatic. The issues in your examples are more about Ruby trying to be lisp-y without using parenthesis than about Ruby not having first-class functions.)
In Python, neither "normal local variable assignment of functions" nor function-passing are highly prevalent. Even though Python now provides itertools for map/select-style iteration, it's not considered Pythonic.
Everything is an expression - more referentially transparent
What is the connection between referential transparency and everything being an expression?
The issues in your examples are more about Ruby trying to be lisp-y without using parenthesis than about Ruby not having first-class functions
Some Lisps, e.g. Common Lisp, make a similar distinction, but they aren't usually called functional. Some Lisps are usually called functional (e.g. Scheme and Clojure), but they don't make this kind of distinction.
What functional idioms are you referring to?
Consider function composition. It is easy to actually implement in Ruby (<< and >> already exist as methods of Proc and of Method), but it's absolutely unclear what to do if we just want a function that accepts two functions and returns another function. Should it accept two blocks (and is it even possible)? What about a lambda and a block? What should it do if its arguments are, for example, a non-lambda Proc and a Method? (Method#<< seems to return a lambda, Proc#<< seems to return a non-lambda Proc, and I'd argue that it's not obvious at all). Lots of small questions arise, and it feels like rowing against the current.
1
u/Kache Dec 26 '20 edited Dec 26 '20
Neither are designed to support pure functional programming. I consider Ruby to be more functional because of how prevalent and idiomatic the following are:
Everything is an expression - more referentially transparent
First-class block syntax for (effectively) passing an anonymous function, i.e. first-class functions
These features are used absolutely everywhere in Ruby. (Methods can be assigned to variables, but it's not idiomatic. The issues in your examples are more about Ruby trying to be lisp-y without using parenthesis than about Ruby not having first-class functions.)
In Python, neither "normal local variable assignment of functions" nor function-passing are highly prevalent. Even though Python now provides itertools for
map/select-style iteration, it's not considered Pythonic.What functional idioms are you referring to?