The cartesian-product-switch Reference Manual

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

The cartesian-product-switch Reference Manual

This is the cartesian-product-switch Reference Manual, version 2.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 03:20:47 2022 GMT+0.

Table of Contents


1 Introduction

Project's home: http://www.hexstreamsoft.com/projects/cartesian-product-switch/


CARTESIAN-PRODUCT-SWITCH is a macro for choosing the appropriate form
to execute according to the combined results of multiple tests. This is a
straightforward and efficient alternative to the convoluted ad-hoc
conditionals one might otherwise resort to.

cartesian-product-switch was born as cartesian-product-case but a
fairly obvious limitation was soon discovered, prompting a redesign
and library name change. Further features and extensibility were also
added.


Here's an example:

(let ((manner :flip) (direction :backward))
  (cartesian-product-switch ((case manner
                               :walk
                               :flip)
                             (case direction
                               :forward
                               :in-place
                               :backward))
    "Walking..."
    (error "Walking in-place is too boring!")
    "Awkwardly walking backwards..."
    "Frontflip!"
    "Jumping in-place."
    "Backflip!"
    (t (error "Don't know how to ~A while going ~A." manner direction))))


Currently supported testclause kinds:
(case ccase ecase typecase ctypecase etypecase if cond svref)

It's also possible to make your own kinds.
Check definitions.lisp in particular for inspiration.
In a nutshell, call (cartesian-product-switch:define operator (args) body),
where BODY must return 3 values:

SELECTION-FORM:
A form evaluating to a non-negative integer less than SELECTION-COUNT.

SELECTION-COUNT:
The number of possibilities this testclause introduces.

DEFAULTP:
If true, then the SELECTION-FORM can evaluate to NIL to trigger the "default".


This library is in the Public Domain.
See the UNLICENSE file for details.


2 Systems

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


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

2.1 cartesian-product-switch

CARTESIAN-PRODUCT-SWITCH is a macro for choosing the appropriate form to execute according to the combined results of multiple tests. This is a straightforward and efficient alternative to the convoluted ad-hoc conditionals one might otherwise resort to.

Author

Jean-Philippe Paradis <hexstream@gmail.com>

License

Public Domain

Version

2.0

Dependency

map-bind (system).

Source

cartesian-product-switch.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


3.1.1 cartesian-product-switch/cartesian-product-switch.asd

Source

cartesian-product-switch.asd.

Parent Component

cartesian-product-switch (system).

ASDF Systems

cartesian-product-switch.


3.1.2 cartesian-product-switch/package.lisp

Source

cartesian-product-switch.asd.

Parent Component

cartesian-product-switch (system).

Packages

cartesian-product-switch.


3.1.3 cartesian-product-switch/info.lisp

Dependency

package.lisp (file).

Source

cartesian-product-switch.asd.

Parent Component

cartesian-product-switch (system).

Public Interface
Internals

3.1.4 cartesian-product-switch/definitions.lisp

Dependency

info.lisp (file).

Source

cartesian-product-switch.asd.

Parent Component

cartesian-product-switch (system).

Internals

%map-with-index (function).


3.1.5 cartesian-product-switch/main.lisp

Dependency

definitions.lisp (file).

Source

cartesian-product-switch.asd.

Parent Component

cartesian-product-switch (system).

Public Interface

cartesian-product-switch (macro).

Internals

4 Packages

Packages are listed by definition order.


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

4.1 cartesian-product-switch

Source

package.lisp.

Nickname

cp-switch

Use List

common-lisp.

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: cartesian-product-switch ((&rest testclauses) &body clauses)
Package

cartesian-product-switch.

Source

main.lisp.

Macro: define (name macro-lambda-list &body body)
Package

cartesian-product-switch.

Source

info.lisp.


5.1.2 Ordinary functions

Function: ensure (name lambda-list expander &rest keys &key class &allow-other-keys)
Package

cartesian-product-switch.

Source

info.lisp.

Function: expand (testclause &optional env)
Package

cartesian-product-switch.

Source

info.lisp.

Function: locate (testclause-name &key errorp)
Package

cartesian-product-switch.

Source

info.lisp.


5.1.3 Generic functions

Generic Reader: expander (object)
Package

cartesian-product-switch.

Source

info.lisp.

Methods
Reader Method: expander ((standard-info standard-info))

automatically generated reader method

Target Slot

%expander.

Generic Reader: lambda-list (object)
Package

cartesian-product-switch.

Source

info.lisp.

Methods
Reader Method: lambda-list ((standard-info standard-info))

automatically generated reader method

Target Slot

%lambda-list.

Generic Reader: name (object)
Package

cartesian-product-switch.

Source

info.lisp.

Methods
Reader Method: name ((standard-info standard-info))

automatically generated reader method

Target Slot

%name.


5.1.4 Classes

Class: info
Package

cartesian-product-switch.

Source

info.lisp.

Direct subclasses

standard-info.

Class: standard-info
Package

cartesian-product-switch.

Source

info.lisp.

Direct superclasses

info.

Direct methods
Direct slots
Slot: %name
Type

cartesian-product-switch::testclause-name

Initargs

:name

Readers

name.

Writers

This slot is read-only.

Slot: %lambda-list
Type

list

Initargs

:lambda-list

Readers

lambda-list.

Writers

This slot is read-only.

Slot: %expander
Type

(or function symbol)

Initargs

:expander

Readers

expander.

Writers

This slot is read-only.


5.2 Internals


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

5.2.1 Special variables

Special Variable: *infos*
Package

cartesian-product-switch.

Source

info.lisp.


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

5.2.2 Ordinary functions

Function: %check-expected-operator (actual expected)
Package

cartesian-product-switch.

Source

info.lisp.

Function: %compute-factors (selection-counts)
Package

cartesian-product-switch.

Source

main.lisp.

Function: %compute-selection-forms (testclauses env else-tag)
Package

cartesian-product-switch.

Source

main.lisp.

Function: %expand-linearize (testclauses env)
Package

cartesian-product-switch.

Source

main.lisp.

Function: %extract-&environment (macro-lambda-list)
Package

cartesian-product-switch.

Source

info.lisp.

Function: (setf %locate) (testclause-name &key errorp)
Package

cartesian-product-switch.

Source

info.lisp.

Function: %make-expander (name macro-lambda-list body)
Package

cartesian-product-switch.

Source

info.lisp.

Function: %map-with-index (mapping-function function arg)
Package

cartesian-product-switch.

Source

definitions.lisp.

Function: %remove-keys (keys plist)
Package

cartesian-product-switch.

Source

info.lisp.


5.2.3 Types

Type: testclause-name ()
Package

cartesian-product-switch.

Source

info.lisp.


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   E   F   G   L   M   N  
Index Entry  Section

%
%check-expected-operator: Private ordinary functions
%compute-factors: Private ordinary functions
%compute-selection-forms: Private ordinary functions
%expand-linearize: Private ordinary functions
%extract-&environment: Private ordinary functions
%make-expander: Private ordinary functions
%map-with-index: Private ordinary functions
%remove-keys: Private ordinary functions

(
(setf %locate): Private ordinary functions

C
cartesian-product-switch: Public macros

D
define: Public macros

E
ensure: Public ordinary functions
expand: Public ordinary functions
expander: Public generic functions
expander: Public generic functions

F
Function, %check-expected-operator: Private ordinary functions
Function, %compute-factors: Private ordinary functions
Function, %compute-selection-forms: Private ordinary functions
Function, %expand-linearize: Private ordinary functions
Function, %extract-&environment: Private ordinary functions
Function, %make-expander: Private ordinary functions
Function, %map-with-index: Private ordinary functions
Function, %remove-keys: Private ordinary functions
Function, (setf %locate): Private ordinary functions
Function, ensure: Public ordinary functions
Function, expand: Public ordinary functions
Function, locate: Public ordinary functions

G
Generic Function, expander: Public generic functions
Generic Function, lambda-list: Public generic functions
Generic Function, name: Public generic functions

L
lambda-list: Public generic functions
lambda-list: Public generic functions
locate: Public ordinary functions

M
Macro, cartesian-product-switch: Public macros
Macro, define: Public macros
Method, expander: Public generic functions
Method, lambda-list: Public generic functions
Method, name: Public generic functions

N
name: Public generic functions
name: Public generic functions

Jump to:   %   (  
C   D   E   F   G   L   M   N