Cycles are an immutable ordered, but unindexed, container type similar to circular lists. Unlike lists, however, cycles are fully bidirectional.
(make-cycle list)
Returns a cycle whose elements are the elements of list. Order is preserved.
(make-cycle-reversed list)
Returns a cycle whose elements are the elements of list. Order is reversed.
(cycle element ...)
Returns a cycle containing elements. Order is preserved.
(cycle->list cycle)
Returns a list whose elements are those of cycle. Order is preserved.
(reversed-cycle->list cycle)
Returns a list whose elements are those of cycle. Order is reversed.
(cycle-unfold continue? successor mapper seed)
Start with an empty list. If the result of applying the predicate continue? to seed is #f, apply make-cycle to the reversed list and return the result. (The list need not actually be created.) Otherwise, apply the procedure mapper to seed. The value of mapper is prepended onto the list. Then get a new seed by applying the procedure successor to seed, and repeat this algorithm.
(cycle? obj)
Returns #t if obj is a cycle, and otherwise returns #f.
(empty-cycle? obj)
Returns #t if obj is an empty cycle, and otherwise returns #f. Empty cycles, like empty strings and vectors, may or may not be eqv?.
(cycle=? equivalence cycle1 cycle2)
Return #t if cycle1 and cycle2 contain the same values (in the sense of the equivalence predicate) in the same order; otherwise return #f.
(cycle=?/rotation equivalence cycle1 cycle2)
Return #t if cycle1 and cycle2 contain the same values (in the sense of the equivalence predicate) in the same order, independent of their rotations; otherwise return #f.
Example: (cycle=? eqv? (cycle 1 2 3) (3 1 2)) => t
(cycle-front cycle)
Returns the element in front of cycle.
(cycle-take cycle k)
Returns a list containing the first k elements of cycle.
(cycle-reverse-take cycle k)
Returns a list containing the last k elements of cycle in reverse order.
(cycle-drop cycle k)
Returns a list containing all but the first k elements of cycle.
(cycle-reverse-drop cycle k)
Returns a list containing all but the last k elements of cycle in reverse order.
(cycle-rotate cycle k)
Returns a cycle obtained from cycle by a rotation of k steps forward, where k is an exact non-negative integer.
(cycle-reverse-rotate cycle k)
Returns a cycle obtained from cycle by a rotation of k steps backward, where k is an exact non-negative integer.
(cycle-rotate-while cycle predicate)
Returns a cycle obtained from cycle by a forward rotation of as many steps as possible while the value of cycle-front satisfies predicate. Returns the number of steps.
(cycle-reversed-rotate-while cycle predicate)
Returns a cycle obtained from cycle by a backward rotation of as many steps as possible while the value of (cycle-front cycle) satisfies predicate. Returns the number of steps.
(cycle-rotate-until cycle predicate)
Returns a cycle obtained from cycle by a forward rotation of as few steps as possible until the value of cycle-front satisfies predicate. Returns the number of steps.
(cycle-reversed-rotate-until cycle predicate)
Returns a cycle obtained from cycle by a backward rotation of as few steps as possible until the value of (cycle-front cycle) satisfies predicate. Returns the number of steps.
(cycle-insert-first cycle obj)
Returns a cycle obtained from cycle, but where obj is added as the first element.
(cycle-insert-last cycle obj)
Returns a cycle obtained from cycle, but where obj is added as the last element.
(cycle-delete-first cycle)
Returns a cycle obtained from cycle, but lacking the first element.
(cycle-delete-last cycle)
Returns a cycle obtained from cycle, but lacking the last element.
(cycle-map proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles and returning a single value. cycle-map applies proc to the elements of the cycle(s) in forward order and returns a cycle of the corresponding results.
(cycle-reverse-map proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles and returning a single value. cycle-map applies proc to the elements of the cycle(s) in backward order and returns a cycle of the corresponding results.
(cycle-for-each proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles. cycle-for-each applies proc to the elements of the cycle(s) in forward order and discards any results. Returns an unspecified value.
(cycle-reverse-for-each proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles. cycle-for-each applies proc to the elements of the cycle(s) in backward orderand discards any results. Returns an unspecified value.
(cycle-fold proc nil cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles, plus one additional argument, and returning a single value. cycle-fold applies proc to the elements of the cycle(s) and the value previously returned by proc. On the first call to proc, the additional argument is nil. Returns the result of the final call to proc.
(cycle-map-steps proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles and returning a single value. cycle-map applies proc to all the rotations of the cycle(s) in forward order and returns a cycle of the corresponding results.
(cycle-reverse-map-steps proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles and returning a single value. cycle-map applies proc to all the rotations of the cycle(s) in backward order and returns a cycle of the corresponding results.
(cycle-for-each-step proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles. cycle-for-each applies proc to all the rotations of the cycle(s) in forward order and discards any results. Returns an unspecified value.
(cycle-reverse-for-each-step proc cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles. cycle-for-each applies proc to all the rotations of the cycle(s) in backward order and discards any results. Returns an unspecified value.
(cycle-fold-step proc nil cycle ...)
It is an error unless all cycles have the same length, and proc is a procedure taking as many arguments as there are cycles, plus one additional argument, and returning a single value. cycle-fold applies proc to all the rotations of the cycle(s) and the value previously returned by proc. On the first call to proc, the additional argument is nil. Returns the result of the final call to proc.
(cycle-length cycle)
Returns the number of elements in cycle.
(cycle-reverse cycle)
Return a cycle containing the same elements as this cycle but in reverse order. Navigating a reversed cycle forward is the same as navigating the original cycle backward.
(cycle-count cycle predicate)
Returns the number of elements of cycle which satisfy predicate.
(cycle-any cycle predicate)
Returns #t if any element of cycle satisfies predicate, and #f otherwise.
(cycle-every cycle predicate)
Returns #t if every element of cycle satisfies predicate, and #f otherwise.
(cycle-filter cycle predicate)
Returns a cycle containing those elements which satisfy predicate. Order is preserved.
(cycle-remove cycle predicate)
Returns a cycle containing those elements which do not satisfy predicate. Order is preserved.
(cycle-partition cycle predicate)
Returns two values, a cycle containing those elements which satisfy predicate, and another cycle containing those elements which do not. Order is preserved.
The cycle composed of elements 1, 2 and 3 with 1 in front can be written as following:
#cycle(1 2 3)