Paste number 138905: racket nested macro indentifier binding

Paste number 138905: racket nested macro indentifier binding
Pasted by: dca
When:8 years, 8 months ago
Share:Tweet this! | http://paste.lisp.org/+2Z6H
Channel:None
Paste contents:
Raw Source | XML | Display As
#lang racket

(define-syntax (forever stx)
  (syntax-case stx ()
    [(forever body ...)
     (with-syntax ([abort (datum->syntax #'forever 'abort)])
       #'(call/cc (lambda (abort)
                    (let loop () body ... (loop)))))])) 

(define-syntax (while stx)
  (syntax-case stx ()
    [(while test body ...)
     (with-syntax (; abort* is accessible as ‘abort’
                   [abort* (datum->syntax #'while 'abort)])
       #'(forever (let (; link the two bindings
                        [abort* abort])
                    (unless test (abort))
                    body ...)))]))

(define (g)
  (while #t (abort)))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.