<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>50189</integer>
    </number>
    <user>
      <string>bsmntbombdood</string>
    </user>
    <title>
      <string>print-chars</string>
    </title>
    <contents>
      <string>(define-structure tape cells pos)

(define (print-chars tape chars)
  (if (null? chars)
      &quot;&quot;
      (shortest
       (map (lambda (using-cell)
	      (let* ((data (print-char tape (car chars) using-cell))
		     (new-tape (cdr data))
		     (code (car data)))
		(string-append code
			       (print-chars new-tape (cdr chars)))))
	    (from-to 0 (- (vector-length (tape-cells tape)) 1))))))

      
(define (print-char tape char using-cell)
  (cons 
   (string-append (if (&lt; using-cell (tape-pos tape))
		      (make-string (- (tape-pos tape) using-cell) #\&lt;)
		      (make-string (- using-cell (tape-pos tape)) #\&gt;))
		  (if (&lt; char (vector-ref (tape-cells tape) using-cell))
		      (make-string (- (vector-ref (tape-cells tape) using-cell) char) #\-)
		      (make-string (- char (vector-ref (tape-cells tape) using-cell)) #\+))
		  &quot;.&quot;)
   (make-tape (let ((v (vector-copy (tape-cells tape))))
		(vector-set! v using-cell char)
		v)
	      using-cell)))

(define (from-to n m)
  (if (= n m)
      (list n)
      (cons n (from-to (+ n 1) m))))

(define (shortest lst)
  (let loop ((lst lst)
	     (shortest #f)
	     (len #f))
    (cond ((null? lst) shortest)
	  ((or (not shortest) (&lt; (string-length (car lst)) len))
	   (loop (cdr lst)
		 (car lst)
		 (string-length (car lst))))
	  (else (loop (cdr lst) shortest len)))))
  </string>
    </contents>
    <universal-time>
      <integer>3403042012</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
  </paste>
</paste-with-annotations>