![]() |
Reinforcement Learning and
Artificial
Intelligence (RLAI) |
tiny-crystal project part 2: call & lookup (read-only and non-virtual) |
call
and lookup
(analogous to scheme's eval
and apply
; see
page 2 of the crystal vocabulary notes) as means for examining the
graph without changing it:(call name path) -->
the
vertex named (via a call to lookup
)
(lookup name path) -->
the vertex named
Hints:
The path can be a scheme list. Don't worry about setting it from
within crystal, just construct it from scheme using ordinary scheme
procedures like list
. Generally, in tiny scheme we
lean heavily on scheme data structures. We use
scheme lists for the path, for names, and for the bodies of the crystal
code (names again) that are stored with virtual connections.
Don't worry about making connections yet (that's for the next two
parts).
This part should be about 40 lines or less of scheme code.
You should test your code first by directly invoking your scheme
procedures call
and lookup
on lists that
are crystal names, as in the examples below. Then try using a driver-loop
such as the one at the end.
#|
testing
these tests continue from where the part 1 testing leaves off.
(define path (make-path (list h)))
(set-succ! h 'x 5)
5
(set-succ! v 'w 11)
(set-succ! h 'w 'x)
(eq? v (call '(v) path))
#t
(call '(v (w)) path)
3
(lookup '(v w) path)
11
(lookup '(v (w)) path)
error
(set-succ! h '(1 2 3 4) 13)
(define the-global-path path)
(driver-loop)
(v w)
11
(v (w))
3
(x)
5
(v x)
3
('(1 2 3 4))
13
|#
(define (driver-loop)
(display "crystal> ")
(let ((name (read)))
(cond ((or (equal? name '(quit))
(equal? name
'(exit))
(equal? name
'(bye)))
(display "thank you for using the
crystal interpreter")
(newline))
(else
(display (call name the-global-path))
(driver-loop)))))
display
.