Scala exercises for beginners I had a lot of fun solving them, particularly trying to use a minimal set of operations (pattern matching, recursion,::, Nil). Solving them with fold/reduce helped to clarify some details, though
Nil is the empty list and the operator '::' appends an element to the beginning. I found quite interesting the fact the pattern matching can match and split the pattern 'element::list' Of course, with a fold is a lot easier:
Yes, ':::' is prohibited, but is the list concatenation operator. In Marc's case, it can be easily replaced by the '::' ("cons") operator.
Totally missed that ::: was in the illegal list. Oops!
I suppose if I were to take it out of my append() then I could just use my append method everywhere else...
Fold is starting to make sense a bit (basically seems to be a tiny DSL for recursion) but I get the feeling that most programmers would rather put their brain through a meat grinder than try to wrap their head around this. [ July 21, 2008: Message edited by: Marc Peabody ]