The trivial-wish Reference Manual

Table of Contents

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

The trivial-wish Reference Manual

This is the trivial-wish Reference Manual, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 04:41:48 2018 GMT+0.


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

1 Introduction

TRIVIAL-WISH

This library allows you to create wishes which are requests for a later computation, and fulfil them at a later time.

Note that this is not threaded, or related to promises and other multiprocessing libraries.

Classes derived from wish:wish contain data, and the computation is performed via the fulfil method you specialize for each class. Different kinds of wishes may be freely mixed.

Why?

There are situations that require delaying computation until later, while more data is gathered. Other times, you may want to batch up a number of computations and perform them together. Rather than keeping track of the data yourself, you can create wish classes containing the data and 'fulfilling' the wishes later.

This pattern occurs often enough (in my opinion) to justify this miniscule library.

Usage

Use (wish:define name slotnames..) to quickly create a wish class with slots to hold your data, or subclass from wish:wish the long way.

Create a wish:fulfil method for your wish.

Wishes must be kept a wish:wishes object -- create a slot or a variable with a reasonable scope, and initialize with (make-instance 'wish:wishes)

Make wishes with (make-instance 'wishname :upon wishlist); they are automatically pushed onto the wishlist.

Continue with your code, possibly setting data in your wish or making other wishes.

Call (wish:fulfil wishes) to finally invoke fulfil method on all the wishes in LIFO order, or in natural order with the optional :lifo nil parameter

Example, literally...

(in-package :trivial-wish)
;; -----------------------------------------------------------------------------
;; We need to keep wishes somewhere.  Wishes are a list, so any reasonable
;; location will do.
;;

(defparameter *star* (make-instance 'wish:wishes))
;;
;; In real life, we would probably place wishes into a slot of some class.
;;
;; -----------------------------------------------------------------------------
;; Now we subclass 'wish' to keep our data...
;;
(wish:define my-wish value1 value2)
;;
;; which is a quick way of doing
;;
;; (defclass my-wish (wish:wish)
;;   ((value1 :initarg :value1 :accessor value1 :initform nil)
;;   (value2 :initarg :value2 :accessor value2 :initform nil)))
;;
;;------------------------------------------------------------------------------
;; Every wish class must have a 'fulfil' method that will be called later.
;;
(defmethod wish:fulfil ((wish my-wish)&key)
  (with-slots (value1 value2) wish
    (format t "~A + ~A = ~A~&" value1 value2 (+ value1 value2))))
;;==============================================================================
;;
;; And here is how to use wishes:
;;
(defun example ()
  ;;----------------------------------------------------------------------------
  ;; We can make a wish like this:
  ;;
  (make-instance 'my-wish :upon *star* :value1 2 :value2 2)
  ;;
  (format t "~&Example of using trivial wishes.~&")
  ;;----------------------------------------------------------------------------
  ;; Or, if we don't know all the data, just put in what we do know:
  ;;
  (let ((partial (make-instance 'my-wish :upon *star* :value1 3 )))
    ;;
    (format t "~&Wishes are being made, but nothing is happening yet.~&")
    ;;--------------------------------------------------------------------------
    ;; and another one:
    ;;
    (make-instance 'my-wish :upon *star* :value1 99 :value2 1)
    ;;
    (format t "~&...~&")
    ;;--------------------------------------------------------------------------
    ;; Ah, let's not forget to fill in the missing data
    ;;
    (setf (value2 partial) 4)); wishes can be modifed or finished at any time...
  ;;----------------------------------------------------------------------------
  ;; Finally, make wishes come true, in original order
  ;;
  (wish:fulfil *star* :lifo nil)
  ;;----------------------------------------------------------------------------
  ;; *stars* is now cleared and ready to accept more wishes.
  )
WISH> (example)
Example of using trivial wishes.
Wishes are being made, but nothing is happening yet.
...
2 + 2 = 4
3 + 4 = 7
99 + 1 = 100
NIL

NOTES

example.lisp file does not load with the package; if you want to run it, compile it yourself.

The fulfil method when invoked on a wish fulfils it. When invoked on an instance of wishes, it calls `(fulfil wish) invoke on every wish in the container.

If your fulfilment logic requires more than just the wish itself you can try to defun the fulfil method in a lexical scope that has access to the data you need.

fulfil allows other keyboards, but I could not think of a way to generalize passing arbitrary data to it in a loop... If more is required, consider that all fulfil does is:

(with-slots (data) wishes
    (mapc #'fulfil (if lifo data (reverse data)))
    (setf data nil))

Just write your own!


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 trivial-wish

Author

StackSmith

License

BSD 2-clause

Description

Create ’wishes’ which are requests to compute something later

Source

trivial-wish.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 trivial-wish.asd

Location

trivial-wish.asd

Systems

trivial-wish (system)


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

3.1.2 trivial-wish/package.lisp

Parent

trivial-wish (system)

Location

package.lisp

Packages

trivial-wish


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

3.1.3 trivial-wish/wish.lisp

Dependency

package.lisp (file)

Parent

trivial-wish (system)

Location

wish.lisp

Exported Definitions
Internal Definitions

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

4 Packages

Packages are listed by definition order.


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

4.1 trivial-wish

Source

package.lisp (file)

Nickname

wish

Use List

common-lisp

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: define NAME &rest SLOTS
Package

trivial-wish

Source

wish.lisp (file)


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

5.1.2 Generic functions

Generic Function: fulfil WISH &key LIFO &allow-other-keys

Perform the requested computation on a wish-derived object

Package

trivial-wish

Source

wish.lisp (file)

Methods
Method: fulfil (WISHES wishes) &key LIFO

Fulfil all wishes. Optionally,
:lifo nil to feverse the native last-in-first-out order; :fun to supply a different function to process each wish


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

5.1.3 Classes

Class: wish ()

Subclass your wish class and specialize (fulfil...) method

Package

trivial-wish

Source

wish.lisp (file)

Direct superclasses

standard-object (class)

Direct methods

initialize-instance (method)

Class: wishes ()

A container for wish-derived objects; can be passed

Package

trivial-wish

Source

wish.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
Direct slots
Slot: data
Readers

data (generic function)

Writers

(setf data) (generic function)


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

5.2 Internal definitions


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

5.2.1 Generic functions

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

trivial-wish

Methods
Method: data (WISHES wishes)

automatically generated reader method

Source

wish.lisp (file)

Method: (setf data) NEW-VALUE (WISHES wishes)

automatically generated writer method

Source

wish.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   F   L   T  
Index Entry  Section

F
File, Lisp, trivial-wish.asd: The trivial-wish<dot>asd file
File, Lisp, trivial-wish/package.lisp: The trivial-wish/package<dot>lisp file
File, Lisp, trivial-wish/wish.lisp: The trivial-wish/wish<dot>lisp file

L
Lisp File, trivial-wish.asd: The trivial-wish<dot>asd file
Lisp File, trivial-wish/package.lisp: The trivial-wish/package<dot>lisp file
Lisp File, trivial-wish/wish.lisp: The trivial-wish/wish<dot>lisp file

T
trivial-wish.asd: The trivial-wish<dot>asd file
trivial-wish/package.lisp: The trivial-wish/package<dot>lisp file
trivial-wish/wish.lisp: The trivial-wish/wish<dot>lisp file

Jump to:   F   L   T  

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

A.2 Functions

Jump to:   (  
D   F   G   M  
Index Entry  Section

(
(setf data): Internal generic functions
(setf data): Internal generic functions

D
data: Internal generic functions
data: Internal generic functions
define: Exported macros

F
fulfil: Exported generic functions
fulfil: Exported generic functions

G
Generic Function, (setf data): Internal generic functions
Generic Function, data: Internal generic functions
Generic Function, fulfil: Exported generic functions

M
Macro, define: Exported macros
Method, (setf data): Internal generic functions
Method, data: Internal generic functions
Method, fulfil: Exported generic functions

Jump to:   (  
D   F   G   M  

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

A.3 Variables

Jump to:   D   S  
Index Entry  Section

D
data: Exported classes

S
Slot, data: Exported classes

Jump to:   D   S  

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

A.4 Data types

Jump to:   C   P   S   T   W  
Index Entry  Section

C
Class, wish: Exported classes
Class, wishes: Exported classes

P
Package, trivial-wish: The trivial-wish package

S
System, trivial-wish: The trivial-wish system

T
trivial-wish: The trivial-wish system
trivial-wish: The trivial-wish package

W
wish: Exported classes
wishes: Exported classes

Jump to:   C   P   S   T   W