@MISC{Rees_thescheme, author = {Jonathan Rees and Jonathan Rees (guest Columnist}, title = {The Scheme of Things}, year = {} }
Years of Citing Articles
Bookmark
OpenURL
Abstract
dentally pass a queue to an operator like length that expects a list, I would like to see a meaningful diagnostic message. 3. Disjointness: One would like to be able write case analyses that discriminate between queues and members of other Scheme types. The first of these is easily addressed: Change the representation of queues so that they are marked as being queues. For example, queues could be represented as three-element vectors, where one element (the first, say) is a unique token: (define queue-unique-token (list 'queue)) (define (make-queue) (vector queue-unique-token '() '())) (define (enqueue! q obj) (if (queue? q) (vector-set! q 1 (cons obj (vector-ref q 1))) (error "expected a queue but found this instead" q))) (define (dequeue! q) ...) (define (queue? obj) (and (vector? obj) (= (vector-length obj) 3) (eq? (vector-ref obj 0) queue-unique-token))) This particular choice of unique token even makes queues easily identifiable when displayed