;;; My class log from Chez-Scheme running in a Geiser-managed buffer. ;;; See scheme-and-evolution-of-lisp.txt for how I installed these. Chez Scheme Version 10.0.0 Copyright 1984-2024 Cisco Systems, Inc. ;; All symbols have only one value in scheme: > + # > (load "cps-examples.scm") > (sum '(1 2 3 4)) Exception: incorrect number of arguments 1 to # Type (debug) to enter the debugger. > (sum '(1 2 3 4) (lambda (x) x)) 10 > (define (id x) x) > (sum '(1 2 3 4) id) 10 > (print-squared-sum '(1 2 3 4) id) 100 > (print-squared-sum '(1 2 3 4 5 6) id) 441 > (load "cnt-tree-cps.scm") ;; The contents of cnt-tree-cps.scm : ; ; (define (count-tree-cps t ctn) ; (if (pair? t) ; (count-tree-cps (car t) ; (lambda (L) (count-tree-cps (cdr t) ; (lambda (R) (ctn (+ L R)))))) ; (ctn 1))) > (count-tree-cps '(1 2 3 4 5) id) ;; umm, I have an off-by-one 6 > (count-tree-cps '() id) ;; indeed I do :( 1 > (treesum '() (lambda (x) x)) 0 > (treesum '(1) (lambda (x) x)) 1 > (treesum '(((1 ((2)))) 3 ((((4))))) id) 10 > (treesum '(((1 ((2)))) 3 ((((4))))) (lambda (x) (* x x)))) 100 > (load "cont-dft.scm") > l ((1 (2)) (((((3))))) 4) > t1 (a (b (d h)) (c e (f i) g)) Exception: variable setq is not bound Type (debug) to enter the debugger. > (set! *saved* '()) > (dft-node t1) a > *saved* (#) > (dft-node t1) ;; OK, I shouldn't have done this: that added another action onto the stack. ;; This will bite me later: instead of seeing 'done I'll see b and other ;; nodes a second time around, as the state at the point of processing ;; (CDR t1) is brought back _precisely_ as it was after the first dft-node ;; call! In a sense, this shows off the power and mechanism of CALL/CC. ;; Still, the fact is, dft-node as written is not supposed to be called again ;; after seeding the tree traversal. Bummer. a > *saved* (# #) ; <<--- yeah, an extra action. > (getnext) b > (getnext) d > t1 (a (b (d h)) (c e (f i) g)) > (getnext) h > (getnext) empty > *saved* (# # #) > (getnext) ;; encountering an empty cdr empty > (getnext) c > (getnext) e > (getnext) f > (getnext) i > (getnext) empty > (getnext) g > (getnext) empty > (getnext) empty > (getnext) ;; This is the spurious continuations from above! b > (getnext) d ;;; Let's reset the state. > (set! *saved* '()) > *saved* () > (let ((i1 (dft-node t1)) (i2 (dft-node t2))) (cons i1 i2)) (a . 1) > (getnext) (a . 2) > (getnext) (a . 3) > (getnext) (a . 6) > (getnext) (a . 7) > (getnext) (a . empty) > (getnext) (a . 4) > (getnext) (a . 5) > (getnext) (a . empty) > (getnext) (a . empty) > (getnext) (b . 1) > (getnext) (b . 2) > (getnext) (b . 3) > t1 (a (b (d h)) (c e (f i) g)) > t2 (1 (2 (3 6 7) 4 5)) ;;; Almost a declarative solver! > (load "amb.scm") Found: (4 3 5) > (load "amb.scm") ; with a printout enabled. (1 1 1) #f #f (2 1 1) #f #t (3 1 1) #f #t (4 1 1) #f #t (5 1 1) #f #t (6 1 1) #f #t (7 1 1) #f #t (1 2 1) #f #f (2 2 1) #f #f (3 2 1) #f #t (4 2 1) #f #t (5 2 1) #f #t (6 2 1) #f #t (7 2 1) #f #t (1 3 1) #f #f (2 3 1) #f #f (3 3 1) #f #f (4 3 1) #f #t (5 3 1) #f #t (6 3 1) #f #t (7 3 1) #f #t (1 4 1) #f #f (2 4 1) #f #f (3 4 1) #f #f (4 4 1) #f #f (5 4 1) #f #t (6 4 1) #f #t (7 4 1) #f #t (1 5 1) #f #f (2 5 1) #f #f (3 5 1) #f #f (4 5 1) #f #f (5 5 1) #f #f (6 5 1) #f #t (7 5 1) #f #t (1 6 1) #f #f (2 6 1) #f #f (3 6 1) #f #f (4 6 1) #f #f (5 6 1) #f #f (6 6 1) #f #f (7 6 1) #f #t (1 7 1) #f #f (2 7 1) #f #f (3 7 1) #f #f (4 7 1) #f #f (5 7 1) #f #f (6 7 1) #f #f (7 7 1) #f #f (1 1 2) #f #f (2 1 2) #f #t (3 1 2) #f #t (4 1 2) #f #t (5 1 2) #f #t (6 1 2) #f #t (7 1 2) #f #t (1 2 2) #f #f (2 2 2) #f #f (3 2 2) #f #t (4 2 2) #f #t (5 2 2) #f #t (6 2 2) #f #t (7 2 2) #f #t (1 3 2) #f #f (2 3 2) #f #f (3 3 2) #f #f (4 3 2) #f #t (5 3 2) #f #t (6 3 2) #f #t (7 3 2) #f #t (1 4 2) #f #f (2 4 2) #f #f (3 4 2) #f #f (4 4 2) #f #f (5 4 2) #f #t (6 4 2) #f #t (7 4 2) #f #t (1 5 2) #f #f (2 5 2) #f #f (3 5 2) #f #f (4 5 2) #f #f (5 5 2) #f #f (6 5 2) #f #t (7 5 2) #f #t (1 6 2) #f #f (2 6 2) #f #f (3 6 2) #f #f (4 6 2) #f #f (5 6 2) #f #f (6 6 2) #f #f (7 6 2) #f #t (1 7 2) #f #f (2 7 2) #f #f (3 7 2) #f #f (4 7 2) #f #f (5 7 2) #f #f (6 7 2) #f #f (7 7 2) #f #f (1 1 3) #f #f (2 1 3) #f #t (3 1 3) #f #t (4 1 3) #f #t (5 1 3) #f #t (6 1 3) #f #t (7 1 3) #f #t (1 2 3) #f #f (2 2 3) #f #f (3 2 3) #f #t (4 2 3) #f #t (5 2 3) #f #t (6 2 3) #f #t (7 2 3) #f #t (1 3 3) #f #f (2 3 3) #f #f (3 3 3) #f #f (4 3 3) #f #t (5 3 3) #f #t (6 3 3) #f #t (7 3 3) #f #t (1 4 3) #f #f (2 4 3) #f #f (3 4 3) #f #f (4 4 3) #f #f (5 4 3) #f #t (6 4 3) #f #t (7 4 3) #f #t (1 5 3) #f #f (2 5 3) #f #f (3 5 3) #f #f (4 5 3) #f #f (5 5 3) #f #f (6 5 3) #f #t (7 5 3) #f #t (1 6 3) #f #f (2 6 3) #f #f (3 6 3) #f #f (4 6 3) #f #f (5 6 3) #f #f (6 6 3) #f #f (7 6 3) #f #t (1 7 3) #f #f (2 7 3) #f #f (3 7 3) #f #f (4 7 3) #f #f (5 7 3) #f #f (6 7 3) #f #f (7 7 3) #f #f (1 1 4) #f #f (2 1 4) #f #t (3 1 4) #f #t (4 1 4) #f #t (5 1 4) #f #t (6 1 4) #f #t (7 1 4) #f #t (1 2 4) #f #f (2 2 4) #f #f (3 2 4) #f #t (4 2 4) #f #t (5 2 4) #f #t (6 2 4) #f #t (7 2 4) #f #t (1 3 4) #f #f (2 3 4) #f #f (3 3 4) #f #f (4 3 4) #f #t (5 3 4) #f #t (6 3 4) #f #t (7 3 4) #f #t (1 4 4) #f #f (2 4 4) #f #f (3 4 4) #f #f (4 4 4) #f #f (5 4 4) #f #t (6 4 4) #f #t (7 4 4) #f #t (1 5 4) #f #f (2 5 4) #f #f (3 5 4) #f #f (4 5 4) #f #f (5 5 4) #f #f (6 5 4) #f #t (7 5 4) #f #t (1 6 4) #f #f (2 6 4) #f #f (3 6 4) #f #f (4 6 4) #f #f (5 6 4) #f #f (6 6 4) #f #f (7 6 4) #f #t (1 7 4) #f #f (2 7 4) #f #f (3 7 4) #f #f (4 7 4) #f #f (5 7 4) #f #f (6 7 4) #f #f (7 7 4) #f #f (1 1 5) #f #f (2 1 5) #f #t (3 1 5) #f #t (4 1 5) #f #t (5 1 5) #f #t (6 1 5) #f #t (7 1 5) #f #t (1 2 5) #f #f (2 2 5) #f #f (3 2 5) #f #t (4 2 5) #f #t (5 2 5) #f #t (6 2 5) #f #t (7 2 5) #f #t (1 3 5) #f #f (2 3 5) #f #f (3 3 5) #f #f (4 3 5) #t #t Found: (4 3 5) >