1 ;;; A basic FIFO queue module.
15 (define (cell val prev next)
18 (define cell-prev cadr)
19 (define cell-next caddr)
20 (define (set-cell-prev! cell prev-cell)
21 (set-car! (cdr cell) prev-cell))
22 (define (set-cell-next! cell next-cell)
23 (set-car! (cddr cell) next-cell))
30 (if (not (null? head))
31 (let ((old-head head))
32 (set! head (cell (car args) '() old-head))
33 (set-cell-prev! old-head head))
36 (set! head (cell (car args) '() '()))
39 (let ((old-tail tail))
40 (set! tail (cell-prev old-tail))
43 (set-cell-next! tail '()))
45 ((empty?) (null? head))
47 (let loop ((this-cell head))
50 (cons (cell-val this-cell)
51 (loop (cell-next this-cell))))))))))
53 (define (fifo-push fifo x)
56 (define (fifo-pop fifo)
59 (define (fifo-empty? fifo)
62 (define (fifo->list fifo)