ChezScheme
ChezScheme copied to clipboard
debugger behaves unexpectedly when using function visibility patterns
The context is the exercises from SICP chapter 2.5 "Systems with Generic Operations" but the function visibility management the text introduces (Example 2) doesn't seem debug-able.
;;;; Example 1: Unexpected
(define functions-a (make-hashtable equal-hash equal?))
((lambda ()
(define (breaker-a x)
(break)
x)
(define (not-breaker-a z)
(breaker-a z))
(hashtable-set! functions-a 'fa not-breaker-a)))
(define (fa x) ((hashtable-ref functions-a 'fa #f) x))
;; > (fa 1)
;; break> i
;; #<continuation in not-breaker-a> : sl
;; continuation: #<system continuation in new-cafe>
;; procedure code: (lambda (z) (breaker-a z))
;; call code: (break)
;; frame variables:
;; 0. z: 1
;;;; Example 2: Unexpected
(define functions-b (make-hashtable equal-hash equal?))
(define (install-b)
(define (breaker-b x)
(break)
x)
(define (not-breaker-b z)
(breaker-b z))
(hashtable-set! functions-b 'fb not-breaker-b))
(install-b)
(define (fb x) ((hashtable-ref functions-b 'fb #f) x))
;; > (fb 1)
;; break> i
;; #<continuation in not-breaker-d> : sl
;; continuation: #<system continuation in new-cafe>
;; procedure code: (lambda (z) (breaker-d z))
;; call code: (break)
;; frame variables:
;; 0. z: 1
;;;; Example 3: Expected
(define functions-c (make-hashtable equal-hash equal?))
(define (breaker-c x)
(break)
x)
(define (not-breaker-c z)
(breaker-c z))
(hashtable-set! functions-c 'fc not-breaker-c)
(define (fc x) ((hashtable-ref functions-c 'fc #f) x))
;; > (fc 1)
;; break> i
;; #<continuation in breaker-c> : sl
;; continuation: #<system continuation in new-cafe>
;; procedure code: (lambda (x) (break) x)
;; call code: (break)
;; frame variables:
;; 0. x: 1
;;;; Example 4: Expected
(define functions-d (make-hashtable equal-hash equal?))
(define (breaker-d x)
(break)
x)
(define (install-d)
(define (not-breaker-d z)
(breaker-d z))
(hashtable-set! functions-d 'fd not-breaker-d))
(install-d)
(define (fd x) ((hashtable-ref functions-d 'fd #f) x))
;; > (fd 1)
;; break> i
;; #<continuation in breaker-d> : sl
;; continuation: #<system continuation in new-cafe>
;; procedure code: (lambda (x) (break) x)
;; call code: (break)
;; frame variables:
;; 0. x: 1
Try disabling cp0 and see if that helps. It may have inlined your procedures.
(run-cp0 (lambda (cp0 x) x))