-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue.tem
19 lines (19 loc) · 1.22 KB
/
queue.tem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(page "Queue operations"
(import "docs/queue0.html")
(newtable "Queue operations"
(def queue "" "Creates a queue." (tests (queue) (type (queue))))
(def destructive enq "obj q" "Adds obj to the end of queue q. Returns the queue as a list. The operation is wrapped in <code>atomic</code>."
(tests (let q (queue) (enq 'a q) (enq '(1 2) q))))
(def destructive enq-limit "obj q [limit]" "Adds obj to the queue q. If the new length would exceed the limit, the first element is dequeued. The new contents of the queue is returned as a list. Note that the length of the queue will either grow by one or remain constant; the queue will not be shortened to the limit. The operation is wrapped in <code>atomic</code>."
(tests "(let q (queue)
(enq-limit 'a q 2)
(enq-limit 'b q 2)
(enq-limit 'c q 2))"))
(def destructive deq "q" "Removes the first element from the queue q and returns the removed element. The operation is wrapped in <code>atomic</code>."
(tests (let q (queue) (enq 'a q) (enq 4 q) (deq q))))
(def qlen "q" "Returns the length of queue q."
(tests (let q (queue) (enq 'a q) (enq 4 q) (deq q) (qlen q))))
(def qlist "q" "Returns the contents of queue q as a list."
(tests (let q (queue) (enq 'a q) (enq '(1 2) q) (qlist q))))
)
)