The cl-itertools Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-itertools Reference Manual

This is the cl-itertools Reference Manual, version 0.2, generated automatically by Declt version 4.0 beta 2 "William Riker" on Tue Nov 15 04:50:40 2022 GMT+0.

Table of Contents


1 Introduction

cl-itertools

This is a port of Python itertools, that is a part of standard library, to CL. Original Python docs: https://docs.python.org/2/library/itertools.html

Also it defines couple of primitives, that make writing iterators in CL a joy (at least, for me).

To avoid collisions with CL names the "i" prefix is added to all functions. Thus, they are:

Defined utils

The summary of things, that make working with iterators more convenient. For examples of use, see cl-itertools.lisp itself.

Technicalities

Iterators are implemented on top of CL-COROUTINE system.

To ease the work with iterators there is a universal "IN-IT" driver for ITERATE

(iter (for i in-it (irange 4 10))
      (collect i))
--> (4 5 6 7 8 9)

To ease definition of new iterators, there is "DEFITER" macro. The syntax is prettly self-explanatory, for example, ICOUNT is defined like

(defiter icount (start &optional (step 1))
  (let ((cur start))
    (iter (while t)
	  (yield cur)
	  (incf cur step))))

On each successful invocation of iterator (underlying iterator coroutine), YIELD form has a value, which is supplied to the coroutine on this invocation.

For example, let's define iterator that just prints whatever is supplied to it (and returns successive integers:

(defiter just-a-printer ()
  (iter (for i from 1)
  	(format t "~a~%" (yield i))))

(defparameter *a* (just-a-printer))
(inext-noexit *a* 'a)
  1
  T
(inext-noexit *a* 'b)
  B
  2
  T
(inext-noexit *a* 'c)
  C
  3
  T

This example also shows use of INEXT-NOEXIT macro, which fetches next value from iterator. Note how symbol A is not printed on first call to INEXT-NOEXIT (because control flow is returned from YIELD, before FORMAT is entered). On second call to INEXT-NOEXIT symbol 'B is correctly printed and the next integer -- 2 -- is returned. Second value T is an artefact of realization.

We can modify this example, so that it would also print symbol A

(defiter just-a-printer ()
  (format t "~a~%" (yield-last-value))
  (iter (for i from 1)
  	(format t "~a~%" (yield i))))

(defparameter *a* (just-a-printer))
(inext-noexit *a* 'a)
  A
  1
  T
(inext-noexit *a* 'b)
  B
  2
  T

For this we need to use (YIELD-LAST-VALUE) macrolet, that always gives the last value, supplied to iterator (to the coroutine) by its caller. Thus, before we encountered any YIELDs in the control flow of the iterator, this value is equal to the value first supplied to the iterator (i.e. 'A).

TODO


2 Systems

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


Previous: , Up: Systems   [Contents][Index]

2.1 cl-itertools

itertools Python lib ported to CL

Author

Alexandr Popolitov <popolit@gmail.com>

License

MIT

Version

0.2

Dependencies
  • cl-coroutine (system).
  • iterate (system).
  • alexandria (system).
Source

cl-itertools.asd.

Child Components

3 Files

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


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 cl-itertools/cl-itertools.asd

Source

cl-itertools.asd.

Parent Component

cl-itertools (system).

ASDF Systems

cl-itertools.

Packages

cl-itertools-system.


3.1.2 cl-itertools/package.lisp

Source

cl-itertools.asd.

Parent Component

cl-itertools (system).

Packages

cl-itertools.


3.1.3 cl-itertools/cl-itertools.lisp

Dependency

package.lisp (file).

Source

cl-itertools.asd.

Parent Component

cl-itertools (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 cl-itertools-system

Source

cl-itertools.asd.

Use List
  • asdf/interface.
  • common-lisp.

4.2 cl-itertools

Source

package.lisp.

Use List
  • cl-coroutine.
  • common-lisp.
  • iterate.
Public Interface
Internals

5 Definitions

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


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


5.1.1 Macros

Macro: coexit! ()
Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: def-launched-iter (name args &body body)
Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: defiter (name args &body body)
Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: inext (iter-var &optional arg)

Iter is supposed to be created using DEFITER or MK-ITER – hence its coro always accepts an arg.

Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: inext-noexit (iter-var &optional arg)

Like INEXT, only when iterator is depleted, return (VALUES NIL NIL) and don’t COEXIT.

Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: inext-or-error (iter-var &optional arg)
Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: lambda-coro (&body body)

The coroutine argument is passed through YIELD macro.

Package

cl-itertools.

Source

cl-itertools.lisp.


5.1.2 Ordinary functions

Function: collect-iter (thing)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: ichain (&rest things)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: icompress (data selectors)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: icount (start &optional step)

start, start + step, start + 2*step, ...

Package

cl-itertools.

Source

cl-itertools.lisp.

Function: icycle (p)

p0, p1, ... plast, p0, p1, ...

Package

cl-itertools.

Source

cl-itertools.lisp.

Function: idropwhile (pred seq)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: ifilter (pred seq)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: ifilterfalse (pred seq)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: igroupby (iterable &optional key)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: imap (func &rest things)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: irange (&rest args)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: irepeat (elem &optional n)

elem, elem, elem, ... endlessly or up to n times

Package

cl-itertools.

Source

cl-itertools.lisp.

Function: istarmap (func seq)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: itakewhile (pred seq)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: izip (&rest things)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: izip-longest (&rest things)
Package

cl-itertools.

Source

cl-itertools.lisp.


5.1.3 Generic functions

Generic Function: mk-iter (thing)
Package

cl-itertools.

Source

cl-itertools.lisp.

Methods
Method: mk-iter ((thing vector))
Method: mk-iter ((thing string))
Method: mk-iter ((thing list))
Method: mk-iter ((thing function))
Method: mk-iter ((thing iterator))
Method: mk-iter (thing)

5.1.4 Conditions

Condition: stop-iteration
Package

cl-itertools.

Source

cl-itertools.lisp.

Direct superclasses

error.


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Macros

Macro: clause-for-in-coro-1 (&key for in-coro with-arg generate)
Package

cl-itertools.

Source

cl-itertools.lisp.

Macro: clause-for-in-it-2 (&key for in-it with-arg generate)
Package

cl-itertools.

Source

cl-itertools.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.2 Ordinary functions

Function: i-printing-count (start &optional step)
Package

cl-itertools.

Source

cl-itertools.lisp.

Function: parse-out-keywords (kwd-lst lambda-list)

Return list (KWD1 KWD2 ... KWDn . OTHER-ARGS) collecting all keyword-looking pairs of arguments in lambda list

Package

cl-itertools.

Source

cl-itertools.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.3 Generic functions

Generic Reader: i-coro (object)
Package

cl-itertools.

Methods
Reader Method: i-coro ((iterator iterator))

automatically generated reader method

Source

cl-itertools.lisp.

Target Slot

coro.

Generic Writer: (setf i-coro) (object)
Package

cl-itertools.

Methods
Writer Method: (setf i-coro) ((iterator iterator))

automatically generated writer method

Source

cl-itertools.lisp.

Target Slot

coro.


Previous: , Up: Internals   [Contents][Index]

5.2.4 Classes

Class: iterator
Package

cl-itertools.

Source

cl-itertools.lisp.

Direct methods
Direct slots
Slot: coro
Initargs

:coro

Readers

i-coro.

Writers

(setf i-coro).


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
C   D   F   G   I   L   M   P  
Index Entry  Section

(
(setf i-coro): Private generic functions
(setf i-coro): Private generic functions

C
clause-for-in-coro-1: Private macros
clause-for-in-it-2: Private macros
coexit!: Public macros
collect-iter: Public ordinary functions

D
def-launched-iter: Public macros
defiter: Public macros

F
Function, collect-iter: Public ordinary functions
Function, i-printing-count: Private ordinary functions
Function, ichain: Public ordinary functions
Function, icompress: Public ordinary functions
Function, icount: Public ordinary functions
Function, icycle: Public ordinary functions
Function, idropwhile: Public ordinary functions
Function, ifilter: Public ordinary functions
Function, ifilterfalse: Public ordinary functions
Function, igroupby: Public ordinary functions
Function, imap: Public ordinary functions
Function, irange: Public ordinary functions
Function, irepeat: Public ordinary functions
Function, istarmap: Public ordinary functions
Function, itakewhile: Public ordinary functions
Function, izip: Public ordinary functions
Function, izip-longest: Public ordinary functions
Function, parse-out-keywords: Private ordinary functions

G
Generic Function, (setf i-coro): Private generic functions
Generic Function, i-coro: Private generic functions
Generic Function, mk-iter: Public generic functions

I
i-coro: Private generic functions
i-coro: Private generic functions
i-printing-count: Private ordinary functions
ichain: Public ordinary functions
icompress: Public ordinary functions
icount: Public ordinary functions
icycle: Public ordinary functions
idropwhile: Public ordinary functions
ifilter: Public ordinary functions
ifilterfalse: Public ordinary functions
igroupby: Public ordinary functions
imap: Public ordinary functions
inext: Public macros
inext-noexit: Public macros
inext-or-error: Public macros
irange: Public ordinary functions
irepeat: Public ordinary functions
istarmap: Public ordinary functions
itakewhile: Public ordinary functions
izip: Public ordinary functions
izip-longest: Public ordinary functions

L
lambda-coro: Public macros

M
Macro, clause-for-in-coro-1: Private macros
Macro, clause-for-in-it-2: Private macros
Macro, coexit!: Public macros
Macro, def-launched-iter: Public macros
Macro, defiter: Public macros
Macro, inext: Public macros
Macro, inext-noexit: Public macros
Macro, inext-or-error: Public macros
Macro, lambda-coro: Public macros
Method, (setf i-coro): Private generic functions
Method, i-coro: Private generic functions
Method, mk-iter: Public generic functions
Method, mk-iter: Public generic functions
Method, mk-iter: Public generic functions
Method, mk-iter: Public generic functions
Method, mk-iter: Public generic functions
Method, mk-iter: Public generic functions
mk-iter: Public generic functions
mk-iter: Public generic functions
mk-iter: Public generic functions
mk-iter: Public generic functions
mk-iter: Public generic functions
mk-iter: Public generic functions
mk-iter: Public generic functions

P
parse-out-keywords: Private ordinary functions

Jump to:   (  
C   D   F   G   I   L   M   P  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   C   S  
Index Entry  Section

C
coro: Private classes

S
Slot, coro: Private classes

Jump to:   C   S