This is the stateless-iterators Reference Manual, version 0.2, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Jul 13 22:03:29 2025 GMT+0.
The main system appears first, followed by any subsystem dependency.
stateless-iterators
Stateless iterators similar to those in Lua (or Julia) language
Vasily Postnicov <shamaz.mazum@gmail.com>
2-clause BSD
0.2
serapeum
(system).
alexandria
(system).
package.lisp
(file).
stateless-iterators.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
stateless-iterators/stateless-iterators.asd
stateless-iterators/package.lisp
stateless-iterators/stateless-iterators.lisp
stateless-iterators/stateless-iterators.asd
stateless-iterators
(system).
stateless-iterators/package.lisp
stateless-iterators
(system).
stateless-iterators/stateless-iterators.lisp
package.lisp
(file).
stateless-iterators
(system).
+empty+
(special variable).
collect
(function).
concat
(function).
consume-one
(function).
count-from
(function).
cycle
(function).
do-iterator
(macro).
drop-while
(function).
enumerate
(function).
every
(function).
filter
(function).
find-if
(function).
foldl
(function).
foldr
(function).
imap
(function).
indices
(function).
iterate
(function).
iterate-for-effects
(function).
iterator
(function).
iterator
(structure).
length
(function).
list->iterator
(function).
make-load-form
(method).
nth
(function).
power
(function).
print-object
(method).
product
(function).
range
(function).
repeat
(function).
replicate
(function).
singleton
(function).
some
(function).
take
(function).
take-while
(function).
undefined
(function).
undefined-value
(condition).
unfold
(function).
vector->iterator
(function).
zip
(function).
zip*
(function).
%constructor=
(method).
concat/next
(function).
constructor-values/generic
(method).
copy-iterator
(function).
count-from/next
(function).
cycle/next
(function).
empty/next
(function).
filter/next
(function).
imap/next
(function).
iterate/next
(function).
iterator-init-state
(reader).
iterator-next
(reader).
list->iterator/next
(function).
product/next
(function).
read-only-struct-slot-names
(method).
repeat/next
(function).
singleton/next
(function).
take-while/next
(function).
take/next
(function).
undefined-value-string
(reader method).
undefined/next
(function).
unfold/next
(function).
vector->iterator/next
(function).
Packages are listed by definition order.
stateless-iterators
common-lisp
.
+empty+
(special variable).
collect
(function).
concat
(function).
consume-one
(function).
count-from
(function).
cycle
(function).
do-iterator
(macro).
drop-while
(function).
enumerate
(function).
every
(function).
filter
(function).
find-if
(function).
foldl
(function).
foldr
(function).
imap
(function).
indices
(function).
iterate
(function).
iterate-for-effects
(function).
iterator
(function).
iterator
(structure).
length
(function).
list->iterator
(function).
nth
(function).
power
(function).
product
(function).
range
(function).
repeat
(function).
replicate
(function).
singleton
(function).
some
(function).
take
(function).
take-while
(function).
undefined
(function).
undefined-value
(condition).
unfold
(function).
vector->iterator
(function).
zip
(function).
zip*
(function).
concat/next
(function).
copy-iterator
(function).
count-from/next
(function).
cycle/next
(function).
empty/next
(function).
filter/next
(function).
imap/next
(function).
iterate/next
(function).
iterator-init-state
(reader).
iterator-next
(reader).
list->iterator/next
(function).
product/next
(function).
repeat/next
(function).
singleton/next
(function).
take-while/next
(function).
take/next
(function).
undefined-value-string
(generic reader).
undefined/next
(function).
unfold/next
(function).
vector->iterator/next
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Execute @c(body) for each value from @c(iterator). The value is
bound to @c(val). This is equal to the following code:
@begin[lang=lisp](code)
(iterate-for-effects
iterator
(lambda (val) ...))
@end(code)
Collect all values from an iterator into a list. This is the inverse of @c(list->iterator).
Concatenate one or more iterators into one iterator.
@begin[lang=lisp](code)
(collect (concat (replicate 3 2) (replicate 1 3))) -> ’(3 3 1 1 1)
@end(code)
Get exactly one value from @c(iterator) and return this value and a
new iterator without this value. If the iterator does not contain
values, return @c(default). Useful when we need to get the first value
which satisfies some condition:
@begin[lang=lisp](code)
(consume-one
(drop-while
#’oddp
(list->iterator ’(1 3 5 7 2 3 5))))
;; => 2, (ITERATOR #<FUNCTION STATELESS-ITERATORS::LIST->ITERATOR/NEXT> (3 5)), T
@end(code)
The third value is a boolean which indicates if the returned value is
not default.
An infinite counting iterator which starts from @c(n) and
increments each next value by 1.
@begin[lang=lisp](code)
(collect (take 4 (count-from 1))) -> ’(1 2 3 4)
@end(code)
Repeat values of @c(iterator) infinitely.
@begin[lang=lisp](code)
(collect (take 5 (cycle (list->iterator ’(1 2 3))))) -> ’(1 2 3 1 2)
@end(code)
Create an iterator which has the same values as in @c(iterator)
but drops initial values which satisfy the @c(predicate).
@begin[lang=lisp](code)
(collect (drop-while #’oddp (list->iterator ’(1 3 8 2 5)))) -> ’(8 2 5)
@end(code)
Creatre an iterator which enumerates values of @c(iterator),
i.e. translates a value @c(x) to a cons cell @c((i . x)) where @c(i)
is an integer which is incremented by 1 starting from 0.
@begin[lang=lisp](code)
(collect (enumerate (replicate 3 2))) -> ’((0 . 3) (1 . 3))
@end(code)
Return @c(t) if @c(predicate) is true for every element contained in the iterator and @c(nil) otherwise.
Create an iterator which returns only those values of @c(iterator)
which satisfy @c(predicate).
@begin[lang=lisp](code)
(collect (take 6 (filter #’oddp (count-from 0)))) -> ’(1 3 5 7 9 11)
@end(code)
Return the first value which satisfies the predicate. The second returned value is an iterator which contains values past this value. You can use @c(drop-while) if the first value is not needed.
Left-associative fold for iterators. The returned value is the same
as for the following, but without consing:
@begin[lang=lisp](code)
(reduce function (collect iterator) :initial-value init)
@end(code)
Right-associative fold for iterators. The returned value is the same
as for the following, but maybe more effective:
@begin[lang=lisp](code)
(reduce function (collect iterator) :initial-value init :from-end t)
@end(code)
Create an iterator which applies @c(function) to values of
@c(iterators). This iterator stops when at least one of @c(iterators) stops.
@begin[lang=lisp](code)
(collect (imap #’+ (list->iterator ’(1 3 8 2)) (count-from 0))) -> ’(1 4 10 5)
@end(code)
For a list of array dimensions, return an iterator which iterates
through all possible indices in the array.
@begin[lang=lisp](code)
(collect (indices ’(3 4 2))) ->
’((0 0 0) (0 0 1) (0 1 0) (0 1 1) (0 2 0) (0 2 1) (0 3 0) (0 3 1) (1 0 0)
(1 0 1) (1 1 0) (1 1 1) (1 2 0) (1 2 1) (1 3 0) (1 3 1) (2 0 0) (2 0 1)
(2 1 0) (2 1 1) (2 2 0) (2 2 1) (2 3 0) (2 3 1))
@end(code)
Create an infinite iterator whose values are @c(x), @c(f(x)),
@c(f(f(x))) and so on.
@begin[lang=lisp](code)
(collect (take 3 (iterate (lambda (x) (/ x 2)) 1))) -> ’(1 1/2 1/4)
@end(code)
Extract a value from @c(iterator) and call @c(function) with that value. Repeat until the next state is @c(stop) and return no values.
Return a number of elements in the iterator
Convert a list to an iterator. This is the inverse of @c(collect).
Get n-th value from an iterator.
@begin[lang=lisp](code)
(nth 4 (count-from 0))
;; => 5, (STATELESS-ITERATORS:ITERATOR #<FUNCTION STATELESS-ITERATORS::COUNT-FROM/NEXT> 6)
@end(code)
For an iterator which contains a set of elements \(A\), return an
iterator which contains all elements of \(A^n\).
@begin[lang=lisp](code)
(collect (power (list->iterator ’(-1 0 1)) 2)) ->
’((-1 -1) (-1 0) (-1 1) (0 -1) (0 0) (0 1) (1 -1) (1 0) (1 1))
@end(code)
Create an iterator which has all possible pairs @c((x . y)) where
@c(x) ∈ @c(outer) and @c(y) ∈ @c(inner).
@begin[lang=lisp](code)
(collect (product (range 1 3) (range 3 5))) -> ’((1 . 3) (1 . 4) (2 . 3) (2 . 4))
@end(code)
Create an iterator which counts from @c(from) to @c(to) (excluding
@c(to)) stepping by @c(step).
@begin[lang=lisp](code)
(collect (range 1 8 2)) -> ’(1 3 5 7)
@end(code)
Create an iterator which repeats @c(value) infinitely.
Create an iterator which repeats @c(value) @c(n) times.
@begin[lang=lisp](code)
(replicate x n) = (take n (repeat x))
@end(code)
Return an iterator containing only one specified value
Return @c(t) if @c(predicate) is true for at least one element contained in the iterator and @c(nil) otherwise.
Create an iterator which takes @c(n) values from @c(iterator) and
stops.
@begin[lang=lisp](code)
(collect (take 3 (list->iterator ’(1 2 3 4)))) -> ’(1 2 3)
(collect (take 3 (list->iterator ’(1)))) -> ’(1)
@end(code)
Create an iterator which returns values from @c(iterator) while
@c(predicate) is true.
@begin[lang=lisp](code)
(collect (take-while #’oddp (list->iterator ’(1 3 8 2 5)))) -> ’(1 3)
@end(code)
When a value is forced out of this iterator, a condition of type @c(undefined-value) is signalled with a supplied text.
When an element is forced from this iterator, it calls a function @c(function) with the current state and uses the first returned value as the element and the second value as a next state. @c(x) is an initial state for iteration. A generation of new values can be stopped if the symbol @c(stop) is the second returned value from @c(function).
These two calls are equivalent:
@begin[lang=lisp](code)
(iterate fn x)
(unfold (lambda (state) (values state (funcall fn state))) x)
@end(code)
Example:
@begin[lang=lisp](code)
(collect
(unfold
(lambda (state)
(values
(* state 2)
(if (< state 5) (1+ state) ’stop)))
1)) -> ’(2 4 6 8)
@end(code)
Convert a vector to an iterator.
Create an iterator which returns consed pairs of values of
@c(iter1) and @c(iter2).
@begin[lang=lisp](code)
(collect (take 3 (zip (count-from 1) (count-from 2)))) -> ’((1 . 2) (2 . 3) (3 . 4))
@end(code)
Create an iterator which returns lists of values from @c(iterators).
@begin[lang=lisp](code)
(collect
(take 3 (zip* (count-from 1)
(count-from 2)
(count-from 3)))) -> ’((1 2 3) (2 3 4) (3 4 5))
@end(code)
A condition signalled by @c(undefined).
error
.
Additional clarification of what happened
common-lisp
.
:string
This slot is read-only.
%read-only-struct
.
function
(alexandria:required-argument (quote stateless-iterators::next))
This slot is read-only.
(alexandria:required-argument (quote stateless-iterators::init-state))
This slot is read-only.
Copy an instance of ITERATOR, optionally overriding some or all of its slots.
undefined-value
)) ¶Jump to: | %
C D E F G I L M N P R S T U V Z |
---|
Jump to: | %
C D E F G I L M N P R S T U V Z |
---|
Jump to: | +
I N S |
---|
Jump to: | +
I N S |
---|
Jump to: | C F I P S U |
---|
Jump to: | C F I P S U |
---|