Skip to content

Commit a930f7c

Browse files
authored
Fixed few typos and syntactic errors
1 parent 39e77a1 commit a930f7c

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

labs/lab06.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pointer pointing to an active number. Brainf\*ck programs specify computations o
1414
| ------ | ---------- | ------- |
1515
| < | < | move pointer to the left by one step |
1616
| > | > | move pointer to the right by one step |
17-
| + | + | increase the active number determined by pointer by one |
18-
| - | - | decrease the active number determined by pointer by one |
17+
| + | + | increase the active number determined by the pointer by one |
18+
| - | - | decrease the active number determined by the pointer by one |
1919
| , | @ | read one number from input and store it |
2020
| . | * | display the active number|
2121
| [ `code`] | [ `code` ] | while the active number is not zero, execute `code` |
2222

23-
As I explained in the lecture, Racket can represent any tree structure as data. Thus we don't need
23+
As I explained in the lecture, Racket can represent any tree structure as data. Thus, we don't need
2424
to write a parser and represent Brainf*ck directly as a list of commands where nested lists recursively represent cycles. The only limitation with this approach is the special meaning of symbols `,`
2525
and `.`
2626
in Racket. So we replace them with symbols `@ *`
@@ -39,16 +39,16 @@ containing a mutable fixed-size vector representing the tape and a number repres
3939
The goal of this lab is to modify my implementation from the lecture so that it is purely functional.
4040
This means you must replace the tape object with a purely functional data structure. Next, the implementation of the interpreter
4141
has to be modified a bit. My implementation creates a global tape that the interpreter modifies during the computation.
42-
However, this is not a purely functional code. Thus the tape has to be a part of the state of the computation included among interpreter's
42+
However, this is not a purely functional code. Thus, the tape has to be a part of the state of the computation included among interpreter's
4343
accumulators.
4444

4545
## Task 1
4646
Create a purely functional representation of the tape of a fixed size with a pointer. I will provide detailed hints on how to proceed.
4747
Define a structure `tape` consisting of three components
4848
`left, val, right`
49-
where `left` is the list representing numbers on the tape stored left from the pointer,
49+
where `left` is the list representing numbers on the tape stored to the left of the pointer,
5050
`val`
51-
represents the active number and `right` is the list representing the number on the right.
51+
represents the active number, and `right` is the list representing the number on the right.
5252

5353
```racket
5454
(struct tape (left val right) #:transparent)
@@ -107,8 +107,8 @@ consisting of numbers 1,2,3,4,5,6,7 with 4 being the active number.
107107
Modify the implementation of the interpreter from the lecture so that it uses your purely functional tape.
108108

109109
::: tip Hint
110-
The implementation from the lecture uses a global mutable tape which is defined once and then only reset when executing a program.
111-
Apart from the tape, the interpreter keeps its state in accumulators `prg`
110+
The implementation from the lecture uses a global mutable tape, which is defined once and then only reset when executing a program.
111+
Apart from the tape, the interpreter keeps its state in the accumulators `prg`
112112
containing remaining commands and `input` storing the remaining input. You have to add one more accumulator tracking the tape.
113113
:::
114114

@@ -122,21 +122,21 @@ For your convenience, my complete implementation is shown below.
122122
#lang racket
123123
124124
;;; Brainf*ck - interpreter
125-
;;; As the symbols ., have their specific meaning in Racket, we replace them by the symbols *@
125+
;;; As the symbols ., have their specific meaning in Racket, we replace them with the symbols *@
126126
127127
;;; Sample Brainf*ck programs
128-
; program reading non-negative numbers on the first two positions and displaying their sum
128+
; program reading non-negative numbers in the first two positions and displaying their sum
129129
(define add-prg
130130
'(@ > @ [- < + >] < *))
131131
132-
; program reading non-negative numbers on the first two positions and displaying their product
132+
; program reading non-negative numbers in the first two positions and displaying their product
133133
(define mul-prg
134134
'(@ > @ < [- > [- > + > + < <] > [- < + >] < <] > > > *))
135135
136-
; constant defining the size of tape
136+
; a constant defining the size of the tape
137137
(define SIZE 10)
138138
139-
; constructor of the object tape of a given size
139+
; a constructor of the object tape of a given size
140140
(define (make-tape size)
141141
(define tape (make-vector size 0)) ; initialize fresh tape
142142
(define ptr 0) ; pointer points to the first element
@@ -171,7 +171,7 @@ For your convenience, my complete implementation is shown below.
171171
(else ((tape 'comma) (car input))
172172
(eval-prg prg (cdr input))))) ; recursive call processing further commands
173173
174-
; evaluates all the commands beside comma
174+
; evaluates all the commands beside the comma
175175
(define (eval-cmd cmd prg input)
176176
(match cmd
177177
['+ (tape 'plus)]
@@ -183,22 +183,22 @@ For your convenience, my complete implementation is shown below.
183183
(eval-prg prg input)) ; recursive call processing further commands
184184
185185
(define (eval-cycle cycle prg input)
186-
(if (= (tape 'dot) 0) ; is cycle is finished?
187-
(eval-prg prg input) ; if yes, recursive call preocessing further commands
186+
(if (= (tape 'dot) 0) ; is the cycle finished?
187+
(eval-prg prg input) ; if yes, recursive call processing further commands
188188
(let ([new-input (eval-prg cycle input)]) ; otherwise evaluate cycle code
189189
(eval-cycle cycle prg new-input)))) ; and execute the cycle again
190190
191191
(define (eval-prg prg input)
192192
(displayln (tape 'tape))
193193
(match prg
194-
[(list) input] ; are all commands processed? if yes, return remaining input
194+
[(list) input] ; are all commands processed? If yes, return the remaining input
195195
[(list '@ rest ...) (eval-comma rest input)]
196196
[(list (? list? cmd) rest ...) (eval-cycle cmd rest input)]
197197
[(list cmd rest ...) (eval-cmd cmd rest input)]))
198198
199199
; executes the given program with the given input
200200
(define (run-prg prg input)
201-
(tape 'reset) ; fill tape by zeros
201+
(tape 'reset) ; fill tape with zeros
202202
(eval-prg prg input) ; evaluate program
203203
(printf "done~n"))
204204
```

0 commit comments

Comments
 (0)