RLAI Reinforcement Learning and Artificial Intelligence (RLAI)

tiny-crystal project part 2: call & lookup (read-only and non-virtual)

[The examples were reworked to give clearer test cases with answers on Nov 26]

Implement the scheme procedures 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


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.

Although the above is true, and can work, i would no longer recommend implementing the path directly as a list.  I recommend implementing it as a tagged pair in which the cdr is the "path-list" -- the list of vertices to look at. Then path lists can be processed non-destructively (without mutation).  --Nov 26

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.


these tests continue from where the part 1 testing leaves off.

(define path (make-path (list h)))
(set-succ! h 'x 5)
(set-succ! v 'w 11)
(set-succ! h 'w 'x)
(eq? v (call '(v) path))
(call '(v (w)) path)
(lookup '(v w) path)
(lookup '(v (w)) path)
(set-succ! h '(1 2 3 4) 13)
(define the-global-path path)
(v w)
(v (w))
(v x)
('(1 2 3 4))


(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")
       (display (call name the-global-path))

Changes since Nov 15:

This part of the project might be a good time to implement the scheme primitives such as + and display.

Extend this Page   How to edit   Style   Subscribe   Notify   Suggest   Help   This open web page hosted at the University of Alberta.   Terms of use  727/0