First Steps with Scheme and Git

Today, I installed Git, joined and published my first two code snippets in Scheme (Lisp dialect).

The main reason to study Scheme is the book Structure and Interpretation of Computer Programs, a computer science classic. And the authors use Scheme to illustrate the concepts throughout the book. The language has a very strange syntax. To illustrate this, I present proudly my first programming exercise, an implementation of Newton’s method to iteratively determine the cube root of a number (also available with syntax highlighting on github).

You want to determine the cube root of x, the variable guess will be modified until it’s third power is pretty close to x.

; Newton method to determine cubic root

(define (cbrt-iter guess x)
  (if (good-enough? guess x)
    (cbrt-iter (improve guess x) x)))

(define (improve guess x)
  (/ (+
       (/ x (square guess))
       (* 2 guess))

(define (good-enough? guess x)
  (< (abs (- (* guess (square guess)) x))

(define (cbrt x)
  (cbrt-iter 1.0 x))

Basically, brackets are everything. The expression (+ 1 1) adds 1 and 1. With define, you can declare a variable or function. It takes some time to get used to. But twisting my brain is a good exercise and hopefully will help me to understand also some higher-level concepts.

The second part of this evening session was installing Git and setting it up to work with my github account. With Ubuntu and some good tutorials, this was easy. It all came down to a few apt-get install commands. My Linux machine is really a good working environment for these kind of tasks.