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

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.

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.

#|
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)))))



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