🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Chapter 2

Started by
40 comments, last by SamLowry 17 years ago
Quote: Original post by Muhammad Haggag
Is there another popular name for 'accumulate'?

fold and reduce are typical names for that function.
Advertisement
Quote: Original post by Muhammad Haggag
Exercise 2.35 is about writing a count-leaves procedure as an accumulation operation. I wrote a recursive solution as follows:
*** Source Snippet Removed ***
Is it possible to get away with a simpler solution? (Not that this one is complex--it isn't. Just wondering)

Kinda hard to answer. In theory, there could be a accumulate function specialized for trees and you could use that. But this logic would lead to absurdities, as you could simply say there's an even more specialized pre-existent function doing exactly the same as what count-leaves is supposed to do, and just call that. That would definitely lead to the simplest code.

So, using accumulate as it's defined in SICP, your code is probably the simplest solution, simplest meaning compact without being cryptic. Maybe you could make it a bit clearer by separating levels of abstraction (by using helper functions), but that's definitely nitpicking. Plus, this separating could lead to very abstract functions which would make things more complicated against.

Time to settle on a single answer for once: "hmmmm... I'm not sure".

This topic is closed to new replies.

Advertisement