Lightweight Scheme Development on macOS

LispKit Queue

Library (lispkit queue) provides an implementation for mutable queues, i.e. mutable FIFO buffers.

(make-queue) [procedure]

Returns a new empty queue.

(queue x ...) [procedure]

Returns a new queue with x on its first position followed by the remaining parameters.

(dequeue! (queue 1 2 3))  ⟹  1 

(queue? obj) [procedure]

Returns #t if obj is a queue; otherwise #f is returned.

(queue-empty? q) [procedure]

Returns #t if queue q is empty.

(queue-size q) [procedure]

Returns the size of queue q, i.e. the number of elements buffered in q.

(queue=? q1 q2) [procedure]

Returns #t if queue q1 has the exact same elements in the same order like queue q2; otherwise, #f is returned.

(enqueue! q x) [procedure]

Inserts element x at the end of queue q.

(queue-front q) [procedure]

Returns the first element in queue q. If the queue is empty, an error is raised.

(dequeue! q) [procedure]

Removes the first element from queue q and returns its value.

(define q (make-queue))
(enqueue! q 1)
(enqueue! q 2)
(dequeue! q)    ⟹  1
(queue-front q) ⟹  2
(queue-size q)  ⟹  1

(queue-clear! q) [procedure]

Removes all elements from queue q.

(queue-copy q) [procedure]

Returns a copy of queue q.

(queue->list q) [procedure]

Returns a list consisting of all elements in queue q in the order they were inserted, i.e. starting with the first element.

(define q (make-queue))
(enqueue! q 1)
(enqueue! q 2)
(enqueue! q 3)
(queue->list q)  ⟹  (1 2 3)

(list->queue l) [procedure]

Returns a new queue consisting of the elements of list l. The first element in l will become the front element of the new queue that is returned.

(dequeue! (list->queue '(1 2 3)))  ⟹  1

(list->queue! s l) [procedure]

Inserts the elements of list l into queue q in the order they appear in the list.

(define q (list->queue '(1 2 3)))
(list->queue! q '(4 5 6))
(queue->list q)  ⟹  (1 2 3 4 5 6)