iScheme, with little iPhone, something beginning with (

Friday, 27th May, 2011

I bought iScheme a while ago, purely for the novelty value, and thought little more of it. The other day I was browsing through The Little Schemer with my son, and we came across an exercise to write a function that adds two numbers, using only operations for add 1, subtract 1, and a test for zero (p. 60).

After taking some time to express our mind-bogglement, we decided that the problem would become more accessible if we thought of the two numbers to be added as two piles of coins, and the operations as “take a coin”, “put a coin”, and “is this pile empty?”

Later that night I couldn’t resist trying it out on my phone:

iScheme iPhone screenshot

iScheme: this little schemer is a perfect companion to The Little Schemer!

I scheme, you scheme, we all scheme on iScheme!

etc.

Immodest as it sounds, I have to say I prefer my implementation to the one in the book (reformatted for exposition):

; my version
; (define pls (lambda (x y)
; (cond ((z0 x) y)
; (else (pls (s1 x)(a1 y))
; ))))

; book version
(define pls (lamdba (x y)
(cond ((z0 y) x)
(else (a1 (pls x (s1 y)))
))))

Why is the book’s version better?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: