Skip to content

Playing God with Scheme

Pretty sensitive issue this – whether man should be allowed to play God or not. I was a debater once, and I’ve pretty much debated this with dozens of arguments from each side. One thing you can’t argue with, though: playing God is fun.

I was playing around with Scheme today (for the uninitiated and/or the young, that is a programming language). I was pretty uninitiated too, which is why I had never bothered to try out Scheme before… but this is the closest to playing God that I have come. Here’s why.

Weird but cool syntax: Almost everything in scheme feels like it must have been created around the beginning of time. Scheme is to C++ what Sanskrit is to Hindi. For instance, here’s how you add two numbers in Scheme:

(+ 2 3)

This seems simple enough to follow at first – but then you realize everything in Scheme follows this rule – and so if you want to write an absolute value function, this is how you do it:

(define (abs x) (if (< x 0) (- x) x))

It all goes downhill from there.

Warp the world: The scheme book I was reading unwisely told me that anything and everything in Scheme was changeable. I did not read a sentence further and went ahead and wrote this out:

(define (+ a b) (* a b))
Setting compiled read-only variable+ can yield to incoherent state

This basically tells the interpreter that I want addition to mean multiplication. Despite the warning that I was entering a demented world, I was overjoyed that this appeared to work. And, sure enough:

(+ 5 10)

Bending the fabric of reality: Upward to enlightenment, I realized that + was just a name, and could really point to anything. We often hear these days that "everything is an object". But really, in Scheme, "everything is what you want it to be". And so, after turning my world upside-down, I turned it inside out.

(define + 2)
Setting compiled read-only variable+ can yield to incoherent state

Which says I want + to be a variable with value 2. For an ideal God, of course, the world would just carry out orders without cursing, but hey, I was just playing God! And was indeed bending the world to my will. And so I can now enter this, which looks positively alien, but is perfectly logical and returns a nice round figure:

(* + (- + +) (/ (* + +) +))

By this time, of course, subjects of the now-warped-and-bent-beyond-recognition world were, as you can imagine, feeling like Neanderthal man presented with the supernova of the Crab Nebula (or bash users presented with the Windows command line), and I thought it was about time to un-warp the world again. Even without restarting the interpreter, this is quite easily done:

(define (+ a b) (- a (- b)))

...and there was light :D (though of course the original + procedure can take any number of arguments, I'll figure that out someday)

If you're feeling down, I heartily recommend an episode of playing God to get you feeling on top of the world.


  1. AC wrote:

    Looks like you had a lot of fun dude. But God has called, and he wants his Scheme back!

    Thursday, August 10, 2006 at 8:50 pm | Permalink
  2. kapil kaisare wrote:

    Sort of reminds me of my first outing with Lisp. :)

    Friday, August 11, 2006 at 11:21 am | Permalink
  3. Deepak Jois wrote:

    What book was that, and does it exist in soft copy :)? Not Structure and Interpretation of Computer Programs(SICP) I hope?

    Sunday, August 13, 2006 at 5:24 pm | Permalink
  4. Anshul wrote:

    Deepak: SICP it is ;)

    Sunday, August 13, 2006 at 5:37 pm | Permalink
  5. antrix wrote:

    Anyone read Diamond Age? There’s a sly reference to Lisp/Scheme in it. A girl is solving puzzles based on Turing machines. One of the puzzles has her “learning a language, which was extremely pithy and made heavy use of parenthesis.” :-)

    Sunday, August 13, 2006 at 11:24 pm | Permalink

Post a Comment

Your email is never published nor shared.