circ-print - ; Procedures for printing circular lists. ; ;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;;; Procedures for printing circular lists. ;; This uses the Common-Lisp syntax: #n=OBJECT defines label n (an ;; unsigned decimal numeral) to be object. Any occurrence of #n# ;; subsequently stands for a structure eq? to OBJECT. ;; ;; For example, if you evaluate ;; ;; (define foo (list 1 2)) ;; (define bar (list foo (list 1 2) foo)) ;; ;; then bar will normally print as ;; ;; ((1 2) (1 2) (1 2)) ;; ;; while (cprint bar) will print ;; ;; (#1=(1 2) (1 2) #1#) ;; ;; The "#1=" defines #1# to stand for foo. Wherever that same pair ;; appears in the list, it is printed as #1#. ;; ;; If you evaluate ;; ;; (define circ (list 1 2 3)) ;; (set-cdr! (cddr circ) (cdr circ)) ;; ;; then circ would normally print as ;; ;; (1 2 3 2 3 2 3 2 3 . .. and so on infinitely) ;; ;; while (cprint circ) will print ;; ;; (1 . #1=(2 3 . #1#)) ;; (define (cprint x) (cprinc x) (newline)) (define (cprinc x) (let ((dictionary '()) (count 1)) (define (prefix context left cdr midvector) (case context ((left) (princ left))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at University of California, Berkeley.

Page1 / 2

circ-print - ; Procedures for printing circular lists. ; ;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online