All Projects → skeeto → predd

skeeto / predd

Licence: Unlicense license
Multimethods for Emacs Lisp

Programming Languages

emacs lisp
2029 projects
Makefile
30231 projects

Elisp Multimethods

This library provides Clojure-style multimethods for Emacs Lisp, supporting multiple dispatch over an ad hoc type hierarchy.

See also: Clojure-style Multimethods in Emacs Lisp.

Example Usage

;; `vector' is the dispatch function for the multimethod `show'

(predd-defmulti show #'vector
  "Return how an animal should respond when shown another animal.")

(predd-defmethod show [:cat :mouse] (a b)
  :chase)

(predd-defmethod show [:cat :dog] (a b)
  :run)

(predd-defmethod show [:dog :cat] (a b)
  :bark)

;; Call the multimethod on some different types

(show :cat :dog)    ; => :run
(show :cat :mouse)  ; => :chase

;; Declare that a tabby is a specific type of cat.

(predd-derive :tabby :cat)

(show :dog :tabby)  ; => :bark
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].