This section describes functions for operating on rings. A ring is a fixed-size data structure that supports insertion, deletion, rotation, and modulo-indexed reference and traversal.
This returns a new ring capable of holding size objects. size should be an integer.
This returns the number of objects that ring currently contains. The value will never exceed that returned by
This returns a new ring which is a copy of ring. The new ring contains the same (
eq) objects as ring.
The newest element in the ring always has index 0. Higher indices correspond to older elements. Indices are computed modulo the ring length. Index −1 corresponds to the oldest element, −2 to the next-oldest, and so forth.
This returns the object in ring found at index index. index may be negative or greater than the ring length. If ring is empty,
ring-refsignals an error.
This inserts object into ring, making it the newest element, and returns object.
If the ring is full, insertion removes the oldest element to make room for the new element.
Remove an object from ring, and return that object. The argument index specifies which item to remove; if it is
nil, that means to remove the oldest item. If ring is empty,
ring-removesignals an error.
This inserts object into ring, treating it as the oldest element. The return value is not significant.
If the ring is full, this function removes the newest element to make room for the inserted element.
If you are careful not to exceed the ring size, you can use the ring as a first-in-first-out queue. For example:
(let ((fifo (make-ring 5))) (mapc (lambda (obj) (ring-insert fifo obj)) '(0 one "two")) (list (ring-remove fifo) t (ring-remove fifo) t (ring-remove fifo))) ⇒ (0 t one t "two")blog comments powered by Disqus