Various comments on problematic aspects of the code.

This commit is contained in:
Eli Barzilay 2010-06-23 15:44:16 -04:00
parent 42c7b2b9d3
commit 8a5bceece1

View File

@ -1,13 +1,20 @@
#lang racket
;; ELI: why is it using the `racket' language?
;; A Queue is a circularly linked list of queue structures.
;; The head of the circle is identified by the distinguished head value.
;; The top of the queue (front of the line) is to the right of the head.
;; The bottom of the queue (back of the line) is to the left of the head.
;; ELI: need to say that this is not thread-safe.
(define-struct queue (value left right) #:mutable)
;; ELI: why is `value' mutable?
;; ELI: why is this needed, if nobody can get a hold of anything other
;; than the head?
(define head (gensym 'queue-head))
;; ELI: if it's a single direction queue, then why is it maintaining
;; bidirectional links?
(define (empty-queue)
(let* ([q (make-queue head #f #f)])
(set-queue-left! q q)
@ -17,16 +24,16 @@
(define (queue-head? q)
(eq? (queue-value q) head))
(define (head-queue? v)
(define (head-queue? v) ; ELI: `queue-head?' and `head-queue?' --??
(and (queue? v) (queue-head? v)))
(define (queue-empty? q)
(and (queue-head? q) (queue-head? (queue-right q))))
(define (nonempty-queue? v)
(and (queue? v)
(queue-head? v)
(queue? (queue-right v))
(and (queue? v) ; \ ELI: ...and this is `head-queue?'
(queue-head? v) ; /
(queue? (queue-right v)) ; ELI: can this ever be false?
(not (queue-head? (queue-right v)))))
(define (enqueue! q v)