[plt-scheme] Bridging the gap: Language needed

From: John Clements (clements at brinckerhoff.org)
Date: Fri Mar 20 14:45:48 EDT 2009

On Mar 19, 2009, at 12:26 PM, Gary Baumgartner wrote:

> One person already asked in private for help running the code.
> It needs language "Pretty Big".
>
> I have to update myself on R6RS, DrScheme 4.X module and #lang stuff.
> Until then, I'll mention more for ambtious readers who might read it:

This is probably simpler than you think: put a

#lang scheme

before your code, and run it in the Module language level.

#lang scheme

(define (?) (error "No."))

(define-syntax -<
   (syntax-rules ()
     ((-<) (?))
     ((-< <e0> . <es>)
      (let ((old-fail ?))
        (let/cc resatisfy
          (set! ? (lambda () (set! ? old-fail) (resatisfy (-< . <es>))))
          <e0>)))))

(+ (-< 1 2) (-< 30 40))

... hit run, everything works "fine".

N.B., though: if you take the use of -< out of the definitions window,  
the ? is once again un-set!-able.  It's probably cleaner to use boxes,  
instead:

#lang scheme

(define (done) (error "No more."))
(define next (box done))
(define (?) ((unbox next)))


(define-syntax -<
   (syntax-rules ()
     ((-<) (?))
     ((-< <e0> . <es>)
      (let ((old-fail (unbox next)))
        (let/cc resatisfy
          (set-box! next (lambda ()
                           (set-box! next old-fail)
                           (resatisfy (-< . <es>))))
          <e0>)))))



Also, this program depends on the language's placement of the  
continuation boundary.  This means that if you put a use of ? into the  
definitions window in your module, then the use of ? will loop.  It's  
probably wiser to use a delimited continuation...



John Clements

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20090320/055d25df/attachment.p7s>

Posted on the users mailing list.