Sdraw:   Cons-Cell Diagrams with Pict
1 Usage
sdraw
7.4

Sdraw: Cons-Cell Diagrams with Pict

Jack Rosenthal <jack@rosenth.al>

 (require sdraw) package: sdraw

Cons-cell diagrams (also called box-and-pointer diagrams) are often used to visually depict pairs and lists, typically in an educational context. For example,a cons-cell diagram for the list '(1 (2 3) 4) can be seen below:

image

Sdraw can be used to automatically create these diagrams using Pict. Inspiration for sdraw comes from the SDRAW program included with David S. Touretzky’s Common Lisp: A Gentle Introduction to Symbolic Computation. Like Touretzky’s program, circular lists and other graph-like structures are supported.

1 Usage

There is only one function provided by sdraw:

procedure

(sdraw obj    
  [#:cell-border-color cell-border-color    
  #:cell-inside-color cell-inside-color    
  #:arrow-color arrow-color    
  #:arrow-thickness arrow-thickness    
  #:arrow-head-size arrow-head-size    
  #:arrow-point-size arrow-point-size    
  #:object-padding object-padding    
  #:cell-inside-size cell-inside-size    
  #:cell-inside-radius cell-inside-radius    
  #:cell-border-radius cell-border-radius    
  #:cell-border-width cell-border-width    
  #:vertical-spacing vertical-spacing    
  #:horizontal-spacing horizontal-spacing    
  #:etc-pict etc-pict    
  #:null-style null-style    
  #:null-thickness null-thickness    
  #:max-depth max-depth    
  #:max-width max-width    
  #:reference-label reference-label])  pict?
  obj : any/c
  cell-border-color : color/c = "Black"
  cell-inside-color : color/c = "White"
  arrow-color : color/c = "Black"
  arrow-thickness : real? = 2.5
  arrow-head-size : real? = 7.5
  arrow-point-size : real? = 7.5
  object-padding : real? = 1
  cell-inside-size : real? = 15
  cell-inside-radius : real? = 1.5
  cell-border-radius : real? = 1.5
  cell-border-width : real? = 2
  vertical-spacing : real? = 25
  horizontal-spacing : real? = 40
  etc-pict : pict-convertible? = (text "etc.")
  null-style : (or/c pict-convertible? '/ '|\| 'x)
   = (typeset-code #'())
  null-thickness : real? = 2.5
  max-depth : (or/c +inf.0 natural-number/c) = +inf.0
  max-width : (or/c +inf.0 natural-number/c) = +inf.0
  reference-label : (-> string? pict-convertible?)
   = default-reference-label
Draws a cons-cell diagram of obj. obj can either be a datum or a syntax object. If a syntax object is given, it will be converted to a datum using syntax->datum.

Pairs are drawn as a box, with arrows going down and right for the car and cdr respectively. If a pict-convertible? is given, it will be drawn directly. Otherwise, it will be converted to a pict? using typeset-code.

Various optional keyword arguments can be given to sdraw to customize the appearance: