Welcome to the CHICKEN Scheme pasting service

while loop added by iisjmii on Sun Aug 26 18:44:41 2012

; While loop that can be broken using 'return'
(define-syntax while
  (ir-macro-transformer
   (lambda (form inject compare?)
     (let ((pred  (cadr form))
           (body  (cddr form)))
       `(let ((called? #f))
          (call/cc (lambda (,(inject 'return))
                       (when (not called?)
                         (set! called? #t)
                         (let loop ()
                           (when ,pred
                             ,@body (loop)))))))))))

(define x 5)
(while (positive? x)
       (display x)
       (set! x (- x 1))
       (if (= x 2) (return #t)))
;=>
;543
;#t

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Name of the most used CHICKEN HTTP server implementation:
Visually impaired? Let me spell it for you (wav file) download WAV