From: Brian Candler Date: 2009-01-13T18:46:41+09:00 Subject: Re: functional programming Mike Gold wrote: > Yet I have found small-scale use of functional concepts to be useful in > ruby, what I have (perhaps confusingly) called functional-style-in-ruby > (but not functional programming per se): liberal use of map, inject, > etc; avoiding unnecessary re-assignments to the same variable; avoiding > gratuitous side-effects; not caring about temporary objects (until an > efficiency concern is proven). The same applies to programming in > general. I don't think you'll find any disagreement there. One of the things I like about Ruby is that it's very easy to pick up in an imperative style, and then one by one, as you "get" each new concept, you can start incorporating them in your programs. (for -> each -> map -> inject -> ...etc) Ruby makes a nice playground for exploring functional concepts (I finally "got" the Y combinator after converting it into Ruby), but the lack of tail recursion and the like means that it is not an efficient environment for large scale use of them. Mapping the problem domain into classes and methods works much better. However, we can probably agree that Ruby does make small imperative programs very easy to write. For example, a basic imperative construct is "do x, then do y, then do z". In Ruby I just write x y z In LISP, "do x" is "(x)", but I couldn't write (x) (y) (z) or even ( (x) (y) (z) ) which will most likely bomb out horribly at runtime (**), but (begin (x) (y) (z) ) That's a special form and a lot of brackets to do something "simple". But on the other hand, for someone coming from a functional background, they might say that the whole concept of "do x, then do y" is rarely if ever needed. Why would you evaluate something, only to throw it away? Different languages suit different people's thought processes. Regards, Brian. (**) I believe this is roughly equivalent to: x.call(y,z) -- Posted via http://www.ruby-forum.com/.