SICP Chapter 1 Solved with Scala

Ok, let us get the facts right. We have not provided solution to each exercise but the solutions that we have provided would be good for you to understand the concepts. It would also help you realize how efficiently we can use higher order functions in Scala.

The Structure and Interpretation of Computer Programs (http://mitpress.mit.edu/sicp/full-text/book/book.html) is a seminal book which helps you reason and understand the structure of computer programs. Though the book has been written a while back but the content is refreshingly applicable to the modern programming languages like Scala.

The github project, provides solutions to the following problems

* Exercise 1.5 and 1.6 at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html
* Exercise 1.10 at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html
* Exercises 1.34, 1.38, 1.41, 1.42 and 1.43 at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-12.html

Here, we reproduce a couple of problems.

As you would notice, this problem has a direct consequence with the way the evaluation is done. There is a difference between the two approaches for applicative-order evaluation or normal-order evaluation.

Let us look at another example where we are composing functions

and the solution would look like

Once you are done with the above, there is a bonus question as well

To see the solution, visit our github repository. If you feel something is missing in tacking the questions do send us your feedback either as a comment to this post or send us a mail on hello@knoldus.com We have omitted the test cases and have used objects to keep the code simple and yet display our understanding. You could write simple ScalaTest cases instead of the println that you see in the code.

Written by 

Vikas is the CEO and Co-Founder of Knoldus Inc. Knoldus does niche Reactive and Big Data product development on Scala, Spark, and Functional Java. Knoldus has a strong focus on software craftsmanship which ensures high-quality software development. It partners with the best in the industry like Lightbend (Scala Ecosystem), Databricks (Spark Ecosystem), Confluent (Kafka) and Datastax (Cassandra). Vikas has been working in the cutting edge tech industry for 20+ years. He was an ardent fan of Java with multiple high load enterprise systems to boast of till he met Scala. His current passions include utilizing the power of Scala, Akka and Play to make Reactive and Big Data systems for niche startups and enterprises who would like to change the way software is developed. To know more, send a mail to hello@knoldus.com or visit www.knoldus.com

Leave a Reply

%d bloggers like this: