Welcome to the CHICKEN Scheme pasting service

calling a macro from a macro added by iisjmii on Sun Aug 26 20:02:03 2012

(define-syntax destruct
  (ir-macro-transformer
   (lambda (form inject compare?)
     (apply (lambda (_ names lst #!rest body)
              `(apply (lambda (,@names)
                 ,@body) ,lst))
            form))))

;While loop that can be broken using 'return'
(define-syntax while
  (ir-macro-transformer
   (lambda (form inject compare?)
     (destruct (_ pred body) form
               `(call/cc (lambda (,(inject 'return))
                           (let loop ()
                             (when ,pred
                               ,@body (loop)))))))))

;=> (while (positive? x) (display x) (set! x (- x 1)) (if (= x 2) (return #t)))
;Error: during expansion of (while ...) - unbound variable: destruct

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the result of `(apply + (list -3 4 2))'?
Visually impaired? Let me spell it for you (wav file) download WAV