The trivial-wish Reference Manual

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

The trivial-wish Reference Manual

This is the trivial-wish Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 06:04:51 2022 GMT+0.

Table of Contents


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!


2 Systems

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


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

2.1 trivial-wish

Create ’wishes’ which are requests to compute something later

Author

StackSmith

License

BSD 2-clause

Source

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

Source

trivial-wish.asd.

Parent Component

trivial-wish (system).

ASDF Systems

trivial-wish.


3.1.2 trivial-wish/package.lisp

Source

trivial-wish.asd.

Parent Component

trivial-wish (system).

Packages

trivial-wish.


3.1.3 trivial-wish/wish.lisp

Dependency

package.lisp (file).

Source

trivial-wish.asd.

Parent Component

trivial-wish (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


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

4.1 trivial-wish

Source

package.lisp.

Nickname

wish

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: define (name &rest slots)
Package

trivial-wish.

Source

wish.lisp.


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.

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


5.1.3 Standalone methods

Method: initialize-instance :after ((wish wish) &key upon)
Source

wish.lisp.


5.1.4 Classes

Class: wish

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

Package

trivial-wish.

Source

wish.lisp.

Direct methods

initialize-instance.

Class: wishes

A container for wish-derived objects; can be passed

Package

trivial-wish.

Source

wish.lisp.

Direct methods
Direct slots
Slot: data
Readers

data.

Writers

(setf data).


5.2 Internals


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

5.2.1 Generic functions

Generic Reader: data (object)
Package

trivial-wish.

Methods
Reader Method: data ((wishes wishes))

automatically generated reader method

Source

wish.lisp.

Target Slot

data.

Generic Writer: (setf data) (object)
Package

trivial-wish.

Methods
Writer Method: (setf data) ((wishes wishes))

automatically generated writer method

Source

wish.lisp.

Target Slot

data.


Appendix A Indexes


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

A.1 Concepts


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

A.3 Variables

Jump to:   D   S  
Index Entry  Section

D
data: Public classes

S
Slot, data: Public classes

Jump to:   D   S