little_cat()

Oct 31, 2007 20:58


/* And then Little Cat A * Took the hat off HIS head. * "It is good I have some one * To help ME," he said. * "This is Little Cat B. * And I keep him about, * And when I need help * Then I let him come out." * And then B said, * "I think we need Little Cat C." * -- "The Cat in the Hat Comes Back" Dr. Seuss */ void little_cat( ( Read more... )

Leave a comment

Comments 2

lindseykuper December 14 2007, 11:02:54 UTC

Ooh, I want to play, too!

(define (little-cat letter)
(if (eq? letter #\Z)
"voom"
(little-cat (integer->char (+ (char->integer letter) 1)))))

(I think the Cat in the Hat books were brilliant. The original book used only 236 unique words! And it's still a joy to read.)

Reply


pixelherder December 15 2007, 07:55:38 UTC
It is fun, I have to admit. While I'm at it, here's a Haskell version:

littleCat 'Z' = "voom"
littleCat letter = littleCat $ succ letter

However it's implemented though, I could definitely see myself throwing such a code snippet (with the quotation from the book in a comment of course!) on a CS 151 type exam and asking what it's an example of and what each branch of the if-statement represents. Who says example code always has to be boring?

Reply


Leave a comment

Up