diff options
-rw-r--r-- | chickadee/queue.scm | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/chickadee/queue.scm b/chickadee/queue.scm index 158ac74..51cec76 100644 --- a/chickadee/queue.scm +++ b/chickadee/queue.scm @@ -1,5 +1,5 @@ ;;; Chickadee Game Toolkit -;;; Copyright © 2017 David Thompson <davet@gnu.org> +;;; Copyright © 2017, 2018 David Thompson <davet@gnu.org> ;;; ;;; Chickadee is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published @@ -22,6 +22,7 @@ #:use-module (chickadee array-list) #:export (make-queue queue? + queue-length queue-empty? enqueue! dequeue!)) @@ -33,9 +34,7 @@ (output queue-output)) (define (display-queue q port) - (format port "#<queue length: ~d>" - (+ (array-list-size (queue-input q)) - (array-list-size (queue-output q))))) + (format port "#<queue length: ~d>" (queue-length q))) (set-record-type-printer! <queue> display-queue) @@ -43,10 +42,14 @@ "Return a new, empty queue." (%make-queue (make-array-list) (make-array-list))) +(define (queue-length q) + "Return the number of elements in Q." + (+ (array-list-size (queue-input q)) + (array-list-size (queue-output q)))) + (define (queue-empty? q) "Return #t if Q is empty." - (and (array-list-empty? (queue-input q)) - (array-list-empty? (queue-output q)))) + (zero? (queue-length q))) (define (enqueue! q item) "Add ITEM to Q." |