a life of coding

Monday, October 17, 2005

Scheming Tortoises

Scheme is a powerful language, and you can have a lot of fun with very little code. Guile is a GNU scheme library for extending applications (think emacs lisp). One of the tutorials is building a simple Logo application (Guile Tortoise Tutorial). This has been "ported" to Cocoa/XCode (GuileTortoise.xcode), so that you can play with it on Mac OS X if you install guile. I recommend DarwinPorts, make sure that you get the 1.1 distribution if you are running 10.4.

Its simple to make some fun designs:




(define (rand-normal avg dist)
(lambda () (inexact->exact (+ avg (* dist (random:normal))))))

(define (rand-uniform max)
(lambda () (random max)))

(define (const x) (lambda () x))

(define (crazy-walk turn-thunk move-thunk)
(tortoise-turn (turn-thunk))
(tortoise-move (move-thunk)))

(define (punctuated-crazy-walk turn-thunk move-thunk)
(tortoise-penup)
(tortoise-move 2)
(tortoise-pendown)
(crazy-walk turn-thunk move-thunk))

(define (go count walk-func turn-thunk move-thunk)
(if (> count 0)
(begin (walk-func turn-thunk move-thunk)
(go (- count 1) walk-func turn-thunk move-thunk))))

(tortoise-reset)
(go 5000 punctuated-crazy-walk
(rand-uniform 360)
(rand-normal 5 1))

0 Comments:

Post a Comment



<$I18N$LinksToThisPost>:

Create a Link

<< Home