From: Louis J Scoras Date: 2005-10-20T04:56:54+09:00 Subject: Re: Functional with Ruby ------=_Part_523_20457396.1129751811651 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Yes, it is ultimately defined recursively, but the complexity is pushed dow= n into the fold* functions. Granted it's a pretty simple recursion, but the point still holds. You can create iterators (isomorphisms, whatever you want to call them) ove= r any arbitrary data structure, then use higher order functions to get the behaviour you want. A more helpful one might be over a binary search tree, create a function which iterates over the nodes, in say infix order. Then you never have to write such boring code ever again. Which is why this: a.inject(0){|sum,i| sum+i} Is preferable to this: def listsum(x) > x.size =3D=3D 0 ? 0 : x[0] + listsum(x[1..-1]) > end The point is that this can be used to define any number of functions over a list, and it's more readable. I'm pulling these out of thin air. Supposed t= o be length and concat... foldr (+ 1) 0 list foldr (.) "" list et cetra. [ I'm sure there's probably more errors in those by the way. I really need to try writing some Haskell again. I'm sick enough to have actually enjoyed implementing state monads =3D) ] ------=_Part_523_20457396.1129751811651--