int Total()
{
return dice.Sum(die => die.FaceValue);
} int Total()
{
return dice.Sum(die => die.FaceValue);
}The exact algorithms aren't the point. It's really something more like "stay idiomatic in the language you are in and keep it simple". Another example is when people start going nuts with lambda in Python; you're really not supposed to do that and there is almost always a better way that doesn't involve lambdas.
As a tangent, while the original author was trying to abstract away the loop, I feel he left too many fragments of the loop behind, such as the start and end conditions. As such, I don't think the sum function is cheating too much, and is in fact the goal. I might describe the Total as "the sum of the dies' face values," instead of the more verbose: "the sum of the dies' face values, starting from the first die and ending at the last die."
In a sense, this runs parallel to your reminder to stay idiomatic: when you sum a list of things, it is common to add them all together, not just some subset. It is this shared understanding which lets us be succinct.
Though I do fear that I'm preaching to the choir :-)
sum(d.faceValue() for d in dice)( loop for die in dice sum ( face-value die ))
Been a while since I've done any lisp, but pretty sure that is how you would probably do it.
+/dice`facevalue