The generators Reference Manual

Table of Contents

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

The generators Reference Manual

This is the generators Reference Manual, version 0.1, generated automatically by Declt version 2.3 "Robert April" on Tue Feb 20 08:44:20 2018 GMT+0.


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

1 Introduction

Generators

Generators is a library that provides python style generators in common lisp, by using cl-cont delimited continuations

This library is more of an interesting toy, though as far as I know it does work. I dont think I have ever used this in application code, though I think that with care, it could be.

Requirements

Gotchas

API

make-generator

Creates a new generator, the body of which can yield values to the calling scope

yield

yield - returns the next value from the generator to the caller

yielding

yielding - yields every value in the passed in generators

Iterate clauses

(for v in-generator gen)

iterates through the values produced by a generator

(FOR node a-node-of-lisp-tree tree)

iterates through all the nodes of a lisp tree eg: '(1 (2 3) 4) generates (1 (2 3) 2 3 4)

(FOR node a-leaf-of-lisp-tree tree)

iterates through all the leaves of a lisp tree eg: '(1 (2 3) 4) generates (1 2 3 4)

Example:

(defun generate-lisp-tree-nodes (trees &optional leaves-only?)
  "Do a depth first traversal of some set of trees yielding every node/leaf "
  (make-generator ()
    (iter (for n in (alexandria:ensure-list trees))
      (etypecase n
        (atom (yield n))
        (list
         (unless leaves-only? (yield n))
         (yielding (generate-lisp-tree-nodes n)))))))

Authors

;; Copyright (c) 2013 Russ Tyndall , Acceleration.net http://www.acceleration.net
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are
;; met:
;;
;;  - Redistributions of source code must retain the above copyright
;;    notice, this list of conditions and the following disclaimer.
;;
;;  - Redistributions in binary form must reproduce the above copyright
;;    notice, this list of conditions and the following disclaimer in the
;;    documentation and/or other materials provided with the distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
;; A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

2 Systems

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


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

2.1 generators

Author

<programmers@acceleration.net>

License

BSD

Description

A common lisp package providing python style generators based on delimited continuations

Version

0.1

Dependencies
Source

generators.asd (file)

Components

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

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 files   [Contents][Index]

3.1.1 generators.asd

Location

generators.asd

Systems

generators (system)

Packages

generators.system


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

3.1.2 generators/packages.lisp

Parent

generators (system)

Location

packages.lisp

Packages

generators


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

3.1.3 generators/generators.lisp

Parent

generators (system)

Location

generators.lisp

Exported Definitions
Internal Definitions

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

4 Packages

Packages are listed by definition order.


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

4.1 generators.system

Source

generators.asd

Use List

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

4.2 generators

Source

packages.lisp (file)

Use List
Exported Definitions
Internal Definitions

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

5 Definitions

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


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

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Macros

Macro: make-generator (&key FINAL-VALUE FINAL-EXCEPTION NAME) &body BODY

returns a function that when called yields the next values. Inside of body, you can yield any number of values that you wish by calling (yield &rest args) which is scoped to the body

Package

generators

Source

generators.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 Functions

Function: generate-lisp-tree-nodes TREES &optional LEAVES-ONLY?

Do a depth first traversal of some set of trees yielding every node

Package

generators

Source

generators.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.3 Generic functions

Generic Function: force GENERATOR

Forces the generator to produce a list of its output

Package

generators

Source

generators.lisp (file)

Methods
Method: force (G generator)
Generic Function: generator CONDITION
Generic Function: (setf generator) NEW-VALUE CONDITION
Package

generators

Methods
Method: generator (CONDITION stop-iteration)
Method: (setf generator) NEW-VALUE (CONDITION stop-iteration)
Source

generators.lisp (file)

Generic Function: next GENERATOR &rest ARGS

Returns the next value of this generator

Package

generators

Source

generators.lisp (file)

Methods
Method: next (GEN generator) &rest ARGS
Generic Function: reset GENERATOR

Restarts the generator from its original continuation

Package

generators

Source

generators.lisp (file)

Methods
Method: reset (GEN generator)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

5.1.4 Conditions

Condition: stop-iteration ()
Package

generators

Source

generators.lisp (file)

Direct superclasses

error (condition)

Direct methods
Direct slots
Slot: generator
Initargs

:generator

Initform

(quote nil)

Readers

generator (generic function)

Writers

(setf generator) (generic function)

Slot: handled?
Initargs

:handled?

Initform

(quote nil)

Readers

handled? (generic function)

Writers

(setf handled?) (generic function)


Previous: , Up: Exported definitions   [Contents][Index]

5.1.5 Classes

Class: generator ()

A class that stores all the needed structure for a generator

Package

generators

Source

generators.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
Direct slots
Slot: continuation

The current continuation of the generator

Initargs

:continuation

Readers

continuation (generic function)

Writers

(setf continuation) (generic function)

Slot: use-final-value?

Should this generator, generate a sigil value when complete
if nil will raise the final-exception (defaults ’stop-iteration)

Initargs

:use-final-value?

Readers

use-final-value? (generic function)

Writers

(setf use-final-value?) (generic function)

Slot: final-value

The value to generate if we are using a final-value instead of raising exceptions

Initargs

:final-value

Readers

final-value (generic function)

Writers

(setf final-value) (generic function)

Slot: final-exception

An exception to raise when we are done iterating (if not using final-value)

Initargs

:final-exception

Initform

(quote generators:stop-iteration)

Readers

final-exception (generic function)

Writers

(setf final-exception) (generic function)

Slot: finished?

Has this generator generated all values?

Initargs

:finished?

Readers

finished? (generic function)

Writers

(setf finished?) (generic function)

Slot: original-continuation

The starting point of this generator

Initargs

:original-continuation

Readers

original-continuation (generic function)

Writers

(setf original-continuation) (generic function)

Slot: name
Initargs

:name

Readers

name (generic function)

Writers

(setf name) (generic function)


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

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Macros

Macro: clause-for-a-leaf-of-lisp-tree-3 &key (FOR NODE) (A-LEAF-OF-LISP-TREE TREE) GENERATE
Package

generators

Source

generators.lisp (file)

Macro: clause-for-a-node-of-lisp-tree-2 &key (FOR NODE) (A-NODE-OF-LISP-TREE TREE) GENERATE
Package

generators

Source

generators.lisp (file)

Macro: clause-for-in-generator-1 &key (FOR NODE) (IN-GENERATOR GEN) GENERATE
Package

generators

Source

generators.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: %mv-gen G

Generates a value from the generator, if the generator throws stop iteration returns (values nil T),
turns off call/cc so that this works

Package

generators

Source

generators.lisp (file)

Function: %stop-iteration GENERATOR
Package

generators

Source

generators.lisp (file)

Function: only-one? LIST
Package

generators

Source

generators.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Generic functions

Generic Function: continuation OBJECT
Generic Function: (setf continuation) NEW-VALUE OBJECT
Package

generators

Methods
Method: continuation (GENERATOR generator)
Method: (setf continuation) NEW-VALUE (GENERATOR generator)

The current continuation of the generator

Source

generators.lisp (file)

Generic Function: final-exception OBJECT
Generic Function: (setf final-exception) NEW-VALUE OBJECT
Package

generators

Methods
Method: final-exception (GENERATOR generator)
Method: (setf final-exception) NEW-VALUE (GENERATOR generator)

An exception to raise when we are done iterating (if not using final-value)

Source

generators.lisp (file)

Generic Function: final-value OBJECT
Generic Function: (setf final-value) NEW-VALUE OBJECT
Package

generators

Methods
Method: final-value (GENERATOR generator)
Method: (setf final-value) NEW-VALUE (GENERATOR generator)

The value to generate if we are using a final-value instead of raising exceptions

Source

generators.lisp (file)

Generic Function: finished? OBJECT
Generic Function: (setf finished?) NEW-VALUE OBJECT
Package

generators

Methods
Method: finished? (GENERATOR generator)
Method: (setf finished?) NEW-VALUE (GENERATOR generator)

Has this generator generated all values?

Source

generators.lisp (file)

Generic Function: handled? CONDITION
Generic Function: (setf handled?) NEW-VALUE CONDITION
Package

generators

Methods
Method: handled? (CONDITION stop-iteration)
Method: (setf handled?) NEW-VALUE (CONDITION stop-iteration)
Source

generators.lisp (file)

Generic Function: name OBJECT
Generic Function: (setf name) NEW-VALUE OBJECT
Package

generators

Methods
Method: name (GENERATOR generator)

automatically generated reader method

Source

generators.lisp (file)

Method: (setf name) NEW-VALUE (GENERATOR generator)

automatically generated writer method

Source

generators.lisp (file)

Generic Function: original-continuation OBJECT
Generic Function: (setf original-continuation) NEW-VALUE OBJECT
Package

generators

Methods
Method: original-continuation (GENERATOR generator)
Method: (setf original-continuation) NEW-VALUE (GENERATOR generator)

The starting point of this generator

Source

generators.lisp (file)

Generic Function: use-final-value? OBJECT
Generic Function: (setf use-final-value?) NEW-VALUE OBJECT
Package

generators

Methods
Method: use-final-value? (GENERATOR generator)
Method: (setf use-final-value?) NEW-VALUE (GENERATOR generator)

Should this generator, generate a sigil value when complete
if nil will raise the final-exception (defaults ’stop-iteration)

Source

generators.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   F   G   L  
Index Entry  Section

F
File, Lisp, generators.asd: The generators<dot>asd file
File, Lisp, generators/generators.lisp: The generators/generators<dot>lisp file
File, Lisp, generators/packages.lisp: The generators/packages<dot>lisp file

G
generators.asd: The generators<dot>asd file
generators/generators.lisp: The generators/generators<dot>lisp file
generators/packages.lisp: The generators/packages<dot>lisp file

L
Lisp File, generators.asd: The generators<dot>asd file
Lisp File, generators/generators.lisp: The generators/generators<dot>lisp file
Lisp File, generators/packages.lisp: The generators/packages<dot>lisp file

Jump to:   F   G   L  

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

A.2 Functions

Jump to:   %   (  
C   F   G   H   M   N   O   R   U  
Index Entry  Section

%
%mv-gen: Internal functions
%stop-iteration: Internal functions

(
(setf continuation): Internal generic functions
(setf continuation): Internal generic functions
(setf final-exception): Internal generic functions
(setf final-exception): Internal generic functions
(setf final-value): Internal generic functions
(setf final-value): Internal generic functions
(setf finished?): Internal generic functions
(setf finished?): Internal generic functions
(setf generator): Exported generic functions
(setf generator): Exported generic functions
(setf handled?): Internal generic functions
(setf handled?): Internal generic functions
(setf name): Internal generic functions
(setf name): Internal generic functions
(setf original-continuation): Internal generic functions
(setf original-continuation): Internal generic functions
(setf use-final-value?): Internal generic functions
(setf use-final-value?): Internal generic functions

C
clause-for-a-leaf-of-lisp-tree-3: Internal macros
clause-for-a-node-of-lisp-tree-2: Internal macros
clause-for-in-generator-1: Internal macros
continuation: Internal generic functions
continuation: Internal generic functions

F
final-exception: Internal generic functions
final-exception: Internal generic functions
final-value: Internal generic functions
final-value: Internal generic functions
finished?: Internal generic functions
finished?: Internal generic functions
force: Exported generic functions
force: Exported generic functions
Function, %mv-gen: Internal functions
Function, %stop-iteration: Internal functions
Function, generate-lisp-tree-nodes: Exported functions
Function, only-one?: Internal functions

G
generate-lisp-tree-nodes: Exported functions
generator: Exported generic functions
generator: Exported generic functions
Generic Function, (setf continuation): Internal generic functions
Generic Function, (setf final-exception): Internal generic functions
Generic Function, (setf final-value): Internal generic functions
Generic Function, (setf finished?): Internal generic functions
Generic Function, (setf generator): Exported generic functions
Generic Function, (setf handled?): Internal generic functions
Generic Function, (setf name): Internal generic functions
Generic Function, (setf original-continuation): Internal generic functions
Generic Function, (setf use-final-value?): Internal generic functions
Generic Function, continuation: Internal generic functions
Generic Function, final-exception: Internal generic functions
Generic Function, final-value: Internal generic functions
Generic Function, finished?: Internal generic functions
Generic Function, force: Exported generic functions
Generic Function, generator: Exported generic functions
Generic Function, handled?: Internal generic functions
Generic Function, name: Internal generic functions
Generic Function, next: Exported generic functions
Generic Function, original-continuation: Internal generic functions
Generic Function, reset: Exported generic functions
Generic Function, use-final-value?: Internal generic functions

H
handled?: Internal generic functions
handled?: Internal generic functions

M
Macro, clause-for-a-leaf-of-lisp-tree-3: Internal macros
Macro, clause-for-a-node-of-lisp-tree-2: Internal macros
Macro, clause-for-in-generator-1: Internal macros
Macro, make-generator: Exported macros
make-generator: Exported macros
Method, (setf continuation): Internal generic functions
Method, (setf final-exception): Internal generic functions
Method, (setf final-value): Internal generic functions
Method, (setf finished?): Internal generic functions
Method, (setf generator): Exported generic functions
Method, (setf handled?): Internal generic functions
Method, (setf name): Internal generic functions
Method, (setf original-continuation): Internal generic functions
Method, (setf use-final-value?): Internal generic functions
Method, continuation: Internal generic functions
Method, final-exception: Internal generic functions
Method, final-value: Internal generic functions
Method, finished?: Internal generic functions
Method, force: Exported generic functions
Method, generator: Exported generic functions
Method, handled?: Internal generic functions
Method, name: Internal generic functions
Method, next: Exported generic functions
Method, original-continuation: Internal generic functions
Method, reset: Exported generic functions
Method, use-final-value?: Internal generic functions

N
name: Internal generic functions
name: Internal generic functions
next: Exported generic functions
next: Exported generic functions

O
only-one?: Internal functions
original-continuation: Internal generic functions
original-continuation: Internal generic functions

R
reset: Exported generic functions
reset: Exported generic functions

U
use-final-value?: Internal generic functions
use-final-value?: Internal generic functions

Jump to:   %   (  
C   F   G   H   M   N   O   R   U  

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

A.3 Variables

Jump to:   C   F   G   H   N   O   S   U  
Index Entry  Section

C
continuation: Exported classes

F
final-exception: Exported classes
final-value: Exported classes
finished?: Exported classes

G
generator: Exported conditions

H
handled?: Exported conditions

N
name: Exported classes

O
original-continuation: Exported classes

S
Slot, continuation: Exported classes
Slot, final-exception: Exported classes
Slot, final-value: Exported classes
Slot, finished?: Exported classes
Slot, generator: Exported conditions
Slot, handled?: Exported conditions
Slot, name: Exported classes
Slot, original-continuation: Exported classes
Slot, use-final-value?: Exported classes

U
use-final-value?: Exported classes

Jump to:   C   F   G   H   N   O   S   U  

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

A.4 Data types

Jump to:   C   G   P   S  
Index Entry  Section

C
Class, generator: Exported classes
Condition, stop-iteration: Exported conditions

G
generator: Exported classes
generators: The generators system
generators: The generators package
generators.system: The generators<dot>system package

P
Package, generators: The generators package
Package, generators.system: The generators<dot>system package

S
stop-iteration: Exported conditions
System, generators: The generators system

Jump to:   C   G   P   S