2 ms·
(define (error . args) #f) (define (class x y z) (lambda (d) (case d ('x x) ('y y) ('z z) (else (error "Invalid slot ~a" d))))) (define obj
by anon_d 16y ago
(define (error . args) #f)
(define (class x y z)
(lambda (d)
(case d ('x x) ('y y) ('z z) (else (error "Invalid slot ~a" d)))))
(define obj (class 'this 'is-a 'test))
(display (obj (read)))
(newline)
The Stalin scheme compiler, if I read the output correctly, makes a
separate type for 'x, 'y, and 'z. Then it does the dispatch using a
switch statement (in the c code) over the three symbol types. This seems
quite resonable to me; The C compiler will probably produce a jump table.
Note that I was unable to get the compiler to produce dispatch code at all
without dispatching on the result of READ.