Sunday, January 15, 2006

No Loop in Scheme

Today I learned that loop is not a keyword in Scheme. I assumed it was from my habit of copying snippets like
'(let loop .... ) from working programs without taking time to RTFM. Since Scheme is a dynamic language, obfuscated forms will work. For example, known names can be repurposed:-

;; testing letrec
(define (monkeys n)
(let letrec ( [x 3] )
(display "Monkey\n")
(if (> x 0)
(letrec (- x 1) ))))

(monkeys 0)

Dorai Sitaram provides a clear example in section 6.2 of Teach Yourself Scheme.