Implementing some bits from the SICP book in Scala