|
|
scott wrote:
>> 2. The second version is very much shorter. (And simpler?)
>
> You made it simpler, I can make the first one simpler too :-)
I was thinking in terms of how you would literally write the source code
in imperative and functional languages.
var total = 0;
var position = list.start();
while (position != null)
{
total = total + position.get_value();
position = position.get_next();
}
Pretty much a verbatim match there.
>> 3. The second version looks like some kind of a riddle. Not a hard
>> riddle, but a somewhat baffling definition all the same.
>
> And seems unnecessarily complex. Why bother going through splitting
> lists and passing them to recursive functions, when all you really need
> to do is loop through all entries and add up the numbers?
And of course, accessing parts of a list requires splitting them, and
recusion isn't looping. ;-)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|