Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
csci71-lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Brian Guadalupe
csci71-lib
Commits
19fcba12
Commit
19fcba12
authored
Mar 20, 2023
by
Brian Guadalupe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly implemented tape-contents function
parent
e2a52251
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
tmachine.rkt
tm/tmachine.rkt
+10
-9
No files found.
tm/tmachine.rkt
View file @
19fcba12
...
@@ -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
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment