Monthly Archives: July 2007

`call/cc’ and Self-modifying Code, in Ruby

If you read Matthias Felleisen’s blog post today about using call/cc to write a generator, and you’re anything like me, you must have thought “Ruby has call/cc; how would I do this in Ruby?” This is my first pass. It works, but it could very well be broken, and I know it can have a […]

Function-scope state in JavaScript

I needed to write some JavaScript that toggles its output. In Scheme it looks like this: (define img-toggler (let ((down? #t)) (lambda () (if down? (begin (set! down? #f) “right.gif”) (begin (set! down? #t) “down.gif”))))) JavaScript doesn’t have `let’ expressions, so I wrote an approximation of one: And used it like this: