[racket] Trace rejects set!

From: michael rice (nowgate at yahoo.com)
Date: Mon Oct 10 13:09:49 EDT 2011

I'm looking at some old Scheme code and find that the code still works under (#lang racket) but trace is unhappy with  the use of set! in the traced function.

set!: cannot modify a constant: next-leaf-generator

 I also tried (#lang r5rs) but  it's unhappy with my require.

(require racket/trace) => expand: unbound identifier in module in: require

What #lang/require must I use to work around this?



#lang racket

(require racket/trace)

(define next-leaf-generator
  (λ (obj eot)
    (letrec ((return #f)
             (cont (λ (x)
                     (recur obj)
                     (set! cont (λ (x) (return eot)))
                     (cont #f)))
             (recur (λ (obj)
                      (if (pair? obj)
                          (for-each recur obj)
                          (call/cc (λ (c)
                                     (set! cont c)
                                     (return obj)))))))
      (λ () (call/cc (λ (ret)
                       (set! return ret)
                       (cont #f)))))))

(define leaf-eq?
  (λ (x y)
    (let* ((eot (list 'eot))
           (xf (next-leaf-generator x eot))
           (yf (next-leaf-generator y eot)))
      (letrec ((loop (λ (x y)
                       (cond ((not (eq? x y)) #f)
                             ((eq? eot x) #t)
                             (else (loop (xf) (yf)))))))
        (loop (xf) (yf))))))

;> (leaf-eq? '(a (b (c))) '((a) b c))
;> (leaf-eq? '(a (b (c))) '((a) b c d))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111010/41e486fd/attachment.html>

Posted on the users mailing list.