Git Product home page Git Product logo

sicpexercisesolutions's Introduction

README: Dean Wampler's Solutions to the SICP Exercises

Dean Wampler ([email protected])

These are solutions for many of the SICP exercises, written in Scheme, Scala, and Clojure and driven by a unit testing library for each language. I didn't solve all the exercises. Also, I didn't solve some of the problems in all three languages (especially those that were proofs, extensions of previous exercises, etc.)

Feedback is welcome.

Updates December 2010

After a long hiatus, I returned to the problems. Starting around exercise 2.74. I've updated the build environment, too:

  • Scala: Now using scala v2.8.1.final and ScalaTest 1.2.
  • Clojure: Now using Clojure 1.2 and Clojure Contrib 1.2.
  • Scheme: Now using Racket 5.0.X (the new name for PLT Scheme).
  • Makefile: Minor refinements.

Running the Solutions

There is a simple Makefile that runs all the solutions. However, it appears that failed tests don't return $? = 1 for all the runtimes (?), so if a particular exercise solution fails, make won't exit.

For running individual script files, use the run.sh files in each language directory, e.g., if your current directory is scheme/ch02 and you want to run the Exercise 2.1 solution, then use ../run.sh ex2.1.scm.

Scheme Solutions

Most of the Scheme solutions use just the features learned up to that point. The only exceptions are a few exercises where I use output functions and the (set! ...) form before the book introduced them, in order to test the exercise results.

I use SchemeUnit as the XUnit tool and run the solutions using PLT Scheme, in particular the mzscheme interpreter. One thing I noticed about this version of scheme; there is no nil defined for empty lists, as used in the book.. I used (list) instead.

Scala Solutions

I'm a self-proclaimed Scala expert: Programming Scala ;) Hence, some of my solutions use idioms that haven't been introduced at that point in the book.

I use Scala v2.8.1 and ScalaTest v1.0 to run the solutions. You'll need to add the scalatest-x.y.jar to the CLASSPATH. I invoke scala interactively, then load and execute files, e.g.,

scala -cp $SCALA_TEST_HOME/scalatest-1.0/scalatest-1.0.jar
scala> :load ex1.3.scala
Loading ex1.3.scala...
f: (Int,Int,Int)Int
import org.scalatest._
import org.scalatest.matchers._
defined module FSpec
Squaring top two of three integers
- should select the top two values, square them, and add the result

(I suppressed some of the output.)

Sometimes I define versions of functions for which JDK implementations already exist, e.g., abs (absolute).

Clojure Solutions

I'm a novice Clojure user, so some of the solutions may be naive!

I switched to the Clojure 1.1 release candidates midstream without difficulty. The exercises probably work fine with 1.0, too. I use the clojure.test package that comes with the distribution to write the exercises as unit tests. To run them, I invoke the REPL, load each exercise solution into the REPL, then run it using the following command:

(run-tests)

Note that (run-tests) runs all the tests that have been defined in the current REPL session, not just test(s) for the last-loaded solution.

As for my Scala solutions, sometimes I define versions of functions for which JDK or Clojure core implementations already exist, e.g., abs (absolute) and even?.

sicpexercisesolutions's People

Contributors

deanwampler avatar chicagoscala avatar

Watchers

Jutiapaboy avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.