The stateless-iterators Reference Manual

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.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 stateless-iterators

Stateless iterators similar to those in Lua (or Julia) language

Author

Vasily Postnicov <>

License

2-clause BSD

Version

0.2

Dependencies
  • serapeum (system).
  • alexandria (system).
Source

stateless-iterators.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 stateless-iterators/stateless-iterators.asd

Source

stateless-iterators.asd.

Parent Component

stateless-iterators (system).

ASDF Systems

stateless-iterators.


3.1.2 stateless-iterators/package.lisp

Source

stateless-iterators.asd.

Parent Component

stateless-iterators (system).

Packages

stateless-iterators.


3.1.3 stateless-iterators/stateless-iterators.lisp

Dependency

package.lisp (file).

Source

stateless-iterators.asd.

Parent Component

stateless-iterators (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 stateless-iterators

Source

package.lisp.

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: +empty+

An empty iterator.

Package

stateless-iterators.

Source

stateless-iterators.lisp.


5.1.2 Macros

Macro: do-iterator ((val iterator) &body body)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.


5.1.3 Ordinary functions

Function: collect (iterator)

Collect all values from an iterator into a list. This is the inverse of @c(list->iterator).

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: concat (&rest iterators)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: consume-one (iterator &optional default)

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.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: count-from (n)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: cycle (iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: drop-while (predicate iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: enumerate (iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: every (predicate iterator)

Return @c(t) if @c(predicate) is true for every element contained in the iterator and @c(nil) otherwise.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: filter (predicate iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: find-if (predicate iterator)

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.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: foldl (function init iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: foldr (function init iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: imap (function &rest iterators)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: indices (dimensions)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: iterate (function x)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: iterate-for-effects (iterator function)

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.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: iterator (next init-state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: length (iterator)

Return a number of elements in the iterator

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: list->iterator (list)

Convert a list to an iterator. This is the inverse of @c(collect).

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: nth (n iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: power (iterator n)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: product (outer inner)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: range (from to &optional step)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: repeat (value)

Create an iterator which repeats @c(value) infinitely.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: replicate (value n)

Create an iterator which repeats @c(value) @c(n) times.

@begin[lang=lisp](code)
(replicate x n) = (take n (repeat x))
@end(code)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: singleton (value)

Return an iterator containing only one specified value

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: some (predicate iterator)

Return @c(t) if @c(predicate) is true for at least one element contained in the iterator and @c(nil) otherwise.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: take (n iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: take-while (predicate iterator)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: undefined (string)

When a value is forced out of this iterator, a condition of type @c(undefined-value) is signalled with a supplied text.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: unfold (function x)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: vector->iterator (vector)

Convert a vector to an iterator.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: zip (iter1 iter2)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: zip* (&rest iterators)

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)

Package

stateless-iterators.

Source

stateless-iterators.lisp.


5.1.4 Standalone methods

Method: make-load-form ((self iterator) &optional env)
Source

stateless-iterators.lisp.

Method: print-object ((object iterator) stream)
Source

stateless-iterators.lisp.


5.1.5 Conditions

Condition: undefined-value

A condition signalled by @c(undefined).

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Direct superclasses

error.

Direct methods

undefined-value-string.

Direct slots
Slot: string

Additional clarification of what happened

Package

common-lisp.

Initargs

:string

Readers

undefined-value-string.

Writers

This slot is read-only.


5.1.6 Structures

Structure: iterator
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Direct superclasses

%read-only-struct.

Direct methods
Direct slots
Slot: next
Type

function

Initform

(alexandria:required-argument (quote stateless-iterators::next))

Readers

iterator-next.

Writers

This slot is read-only.

Slot: init-state
Initform

(alexandria:required-argument (quote stateless-iterators::init-state))

Readers

iterator-init-state.

Writers

This slot is read-only.


5.2 Internals


5.2.1 Ordinary functions

Function: concat/next (state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: copy-iterator (iterator1 &key next init-state)

Copy an instance of ITERATOR, optionally overriding some or all of its slots.

Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: count-from/next (state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: cycle/next (next first-state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: empty/next (state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: filter/next (next predicate)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: imap/next (nexts function)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: iterate/next (function)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Reader: iterator-init-state (instance)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Target Slot

init-state.

Reader: iterator-next (instance)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Target Slot

next.

Function: list->iterator/next (list)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: product/next (next-outer next-inner init-state-inner)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: repeat/next (value)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: singleton/next (state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: take-while/next (next predicate)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: take/next (n next)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: undefined/next (state)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: unfold/next (function)
Package

stateless-iterators.

Source

stateless-iterators.lisp.

Function: vector->iterator/next (vector)
Package

stateless-iterators.

Source

stateless-iterators.lisp.


5.2.2 Generic functions

Generic Reader: undefined-value-string (condition)
Package

stateless-iterators.

Methods
Reader Method: undefined-value-string ((condition undefined-value))
Source

stateless-iterators.lisp.

Target Slot

string.


5.2.3 Standalone methods

Method: %constructor= ((o1 iterator) (o2 iterator))
Package

serapeum.

Source

stateless-iterators.lisp.

Method: constructor-values/generic ((x iterator))
Package

serapeum.

Source

stateless-iterators.lisp.

Method: read-only-struct-slot-names append ((self iterator))
Package

serapeum.

Source

stateless-iterators.lisp.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   %  
C   D   E   F   G   I   L   M   N   P   R   S   T   U   V   Z  
Index Entry  Section

%
%constructor=: Private standalone methods

C
collect: Public ordinary functions
concat: Public ordinary functions
concat/next: Private ordinary functions
constructor-values/generic: Private standalone methods
consume-one: Public ordinary functions
copy-iterator: Private ordinary functions
count-from: Public ordinary functions
count-from/next: Private ordinary functions
cycle: Public ordinary functions
cycle/next: Private ordinary functions

D
do-iterator: Public macros
drop-while: Public ordinary functions

E
empty/next: Private ordinary functions
enumerate: Public ordinary functions
every: Public ordinary functions

F
filter: Public ordinary functions
filter/next: Private ordinary functions
find-if: Public ordinary functions
foldl: Public ordinary functions
foldr: Public ordinary functions
Function, collect: Public ordinary functions
Function, concat: Public ordinary functions
Function, concat/next: Private ordinary functions
Function, consume-one: Public ordinary functions
Function, copy-iterator: Private ordinary functions
Function, count-from: Public ordinary functions
Function, count-from/next: Private ordinary functions
Function, cycle: Public ordinary functions
Function, cycle/next: Private ordinary functions
Function, drop-while: Public ordinary functions
Function, empty/next: Private ordinary functions
Function, enumerate: Public ordinary functions
Function, every: Public ordinary functions
Function, filter: Public ordinary functions
Function, filter/next: Private ordinary functions
Function, find-if: Public ordinary functions
Function, foldl: Public ordinary functions
Function, foldr: Public ordinary functions
Function, imap: Public ordinary functions
Function, imap/next: Private ordinary functions
Function, indices: Public ordinary functions
Function, iterate: Public ordinary functions
Function, iterate-for-effects: Public ordinary functions
Function, iterate/next: Private ordinary functions
Function, iterator: Public ordinary functions
Function, iterator-init-state: Private ordinary functions
Function, iterator-next: Private ordinary functions
Function, length: Public ordinary functions
Function, list->iterator: Public ordinary functions
Function, list->iterator/next: Private ordinary functions
Function, nth: Public ordinary functions
Function, power: Public ordinary functions
Function, product: Public ordinary functions
Function, product/next: Private ordinary functions
Function, range: Public ordinary functions
Function, repeat: Public ordinary functions
Function, repeat/next: Private ordinary functions
Function, replicate: Public ordinary functions
Function, singleton: Public ordinary functions
Function, singleton/next: Private ordinary functions
Function, some: Public ordinary functions
Function, take: Public ordinary functions
Function, take-while: Public ordinary functions
Function, take-while/next: Private ordinary functions
Function, take/next: Private ordinary functions
Function, undefined: Public ordinary functions
Function, undefined/next: Private ordinary functions
Function, unfold: Public ordinary functions
Function, unfold/next: Private ordinary functions
Function, vector->iterator: Public ordinary functions
Function, vector->iterator/next: Private ordinary functions
Function, zip: Public ordinary functions
Function, zip*: Public ordinary functions

G
Generic Function, undefined-value-string: Private generic functions

I
imap: Public ordinary functions
imap/next: Private ordinary functions
indices: Public ordinary functions
iterate: Public ordinary functions
iterate-for-effects: Public ordinary functions
iterate/next: Private ordinary functions
iterator: Public ordinary functions
iterator-init-state: Private ordinary functions
iterator-next: Private ordinary functions

L
length: Public ordinary functions
list->iterator: Public ordinary functions
list->iterator/next: Private ordinary functions

M
Macro, do-iterator: Public macros
make-load-form: Public standalone methods
Method, %constructor=: Private standalone methods
Method, constructor-values/generic: Private standalone methods
Method, make-load-form: Public standalone methods
Method, print-object: Public standalone methods
Method, read-only-struct-slot-names: Private standalone methods
Method, undefined-value-string: Private generic functions

N
nth: Public ordinary functions

P
power: Public ordinary functions
print-object: Public standalone methods
product: Public ordinary functions
product/next: Private ordinary functions

R
range: Public ordinary functions
read-only-struct-slot-names: Private standalone methods
repeat: Public ordinary functions
repeat/next: Private ordinary functions
replicate: Public ordinary functions

S
singleton: Public ordinary functions
singleton/next: Private ordinary functions
some: Public ordinary functions

T
take: Public ordinary functions
take-while: Public ordinary functions
take-while/next: Private ordinary functions
take/next: Private ordinary functions

U
undefined: Public ordinary functions
undefined-value-string: Private generic functions
undefined-value-string: Private generic functions
undefined/next: Private ordinary functions
unfold: Public ordinary functions
unfold/next: Private ordinary functions

V
vector->iterator: Public ordinary functions
vector->iterator/next: Private ordinary functions

Z
zip: Public ordinary functions
zip*: Public ordinary functions