From: John Carter Date: 2005-10-20T06:07:19+09:00 Subject: Re: Functional with Ruby On Thu, 20 Oct 2005, Andreas Semt wrote: > Which is the best way to say it in Ruby (functional style)? I'm not going to answer your concrete question. I'm going to answer the question you should be asking.... The answer is with the exception of the the non '!' string methods and numbers most of ruby operations are non-"functional pure" in the sense that they have side effects and change state. Thus to recapture "functional" programming purity in Ruby, for most objects and operations on them requires you to make very heavy use of the clone method. ie. Force yourself to go obj.clone.operation to make ruby into something like the "Self" language. Certainly in some contexts (eg. when you can prove there are no other references to the object in question) a clone + modify is equivalent to just a modify. Thus you can make an optimization in such cases, but you will receive very little support from the language in proving this. It doesn't even have C++'s "const" keyword. Although it does have "freeze", which unfortunately only works at run time after the object has been frozen, which tends to be a bit late. On the other hand ruby is a "functional" language in the sense that procs, blocks and methods, etc are all first order objects and you can curry dice and slice them. It even has several flavours of eval. John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter@tait.co.nz New Zealand Carter's Clarification of Murphy's Law. "Things only ever go right so that they may go more spectacularly wrong later." From this principle, all of life and physics may be deduced.