Commit 19fcba12 authored by Brian Guadalupe's avatar Brian Guadalupe

Properly implemented tape-contents function

parent e2a52251
...@@ -103,11 +103,13 @@ ...@@ -103,11 +103,13 @@
(tape-list->string (cdr (tape-after tape)))))) (tape-list->string (cdr (tape-after tape))))))
(define (tape-contents tm) (define (tape-contents tm)
(let ([tape (tm-config-tape tm)]) (let* ([tape (tm-config-tape tm)]
(format "~a~a~a" [before (reverse (tape-before tape))]
(tape-list->string (reverse (tape-before tape))) [after (cdr (tape-after tape))])
(tape-head tape) (string-split
(tape-list->string (cdr (tape-after tape)))))) (apply string-append
(map (λ (s) (if (eq? s BLANK) " " (format "~a" s)))
(append before (list (tape-head tape)) after))))))
;; program-related stuff ;; program-related stuff
...@@ -181,10 +183,10 @@ ...@@ -181,10 +183,10 @@
(> (tm-config-steps tm) MAX-STEPS)) (> (tm-config-steps tm) MAX-STEPS))
(error (format "TM still running after ~a steps; double-check for possible infinite loop" (error (format "TM still running after ~a steps; double-check for possible infinite loop"
MAX-STEPS))) MAX-STEPS)))
(printf "~a\n\t" (stmt->string (vector-ref (tm-config-program tm) ;(printf "~a\n\t" (stmt->string (vector-ref (tm-config-program tm)
(tm-config-line-no tm)))) ; (tm-config-line-no tm))))
(step! tm) (step! tm)
(print-tape tm) ;(print-tape tm)
;(printf "tape position: ~a" (tape-pos (tm-config-tape tm))) ;(printf "tape position: ~a" (tape-pos (tm-config-tape tm)))
(if (not (eq? (tm-config-state tm) 'running)) (if (not (eq? (tm-config-state tm) 'running))
(tm-config-state tm) (tm-config-state tm)
...@@ -199,4 +201,3 @@ ...@@ -199,4 +201,3 @@
(define (set-input! tm input) (define (set-input! tm input)
(set-tm-config-tape! tm (initial-tape-for input))) (set-tm-config-tape! tm (initial-tape-for input)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment