Liking cljdoc? Tell your friends :D

methodical.impl.combo.operator

Method combinations strategies based on the non-default method combination types in CLOS. All non-default method combinations follow the same basic pattern:

(operator (primary-method-1 args) (primary-method-2 args) (primary-method-3 args)))

(Example from "Object-Oriented Programming in Common Lisp", Keene 1988.)

The non-default method combinations each support primary methods and :around methods, but not :before or :after. Unlike the standard combination, primary methods do not support call-next-method (next-method in Methodical).

There are 9 built-in method combinations types in CLOS, excluding standard: progn, append, list, nconc, and, or, max, min, and +. These are mostly the same in the implementation below, with the following exceptions:

  • The progn combo is instead named do, which you probably could have guessed.

  • list has been replaced by seq, which returns a lazy sequence -- a very Clojurey improvement.

  • Both nconc and append concatenate lists, but nconc does it destructively; append copies all arguments except the last. The Clojure equivalent of either is concat which is what I have named the method combination below. We actually do one better than CLOS and return a lazy sequence, but lazy-cat seemed like a cumbersome name for the combo.

One last difference: unlike CLOS operator method combinations, primary method implementations are not qualfied by their operator.

;; CLOS (defmethod total-electric-supply + ((city city)) ...)

;; Methodical (defmethod total-electric-supply :city [city] ...)

Method combinations strategies based on the non-default method combination types in CLOS. All non-default method
combinations follow the same basic pattern:

  (operator (primary-method-1 args)
            (primary-method-2 args)
            (primary-method-3 args)))

(Example from "Object-Oriented Programming in Common Lisp", Keene 1988.)

The non-default method combinations each support primary methods and `:around` methods, but not `:before` or
`:after`. Unlike the standard combination, primary methods do not support `call-next-method` (`next-method` in
Methodical).

There are 9 built-in method combinations types in CLOS, excluding `standard`: `progn`, `append`, `list`, `nconc`,
`and`, `or`, `max`, `min`, and `+`. These are mostly the same in the implementation below, with the following
exceptions:

* The `progn` combo is instead named `do`, which you probably could have guessed.

* `list` has been replaced by `seq`, which returns a lazy sequence -- a very Clojurey improvement.

* Both `nconc` and `append` concatenate lists, but `nconc` does it destructively; `append` copies all arguments
  except the last. The Clojure equivalent of either is `concat` which is what I have named the method combination
  below. We actually do one better than CLOS and return a lazy sequence, but `lazy-cat` seemed like a cumbersome name
  for the combo.

One last difference: unlike CLOS operator method combinations, primary method implementations *are not* qualfied by
their operator.

  ;; CLOS
  (defmethod total-electric-supply + ((city city))
    ...)

  ;; Methodical
  (defmethod total-electric-supply :city
    [city]
    ...)
raw docstring

defoperatorcljmacro

(defoperator operator-name [methods-binding invoke-binding] & body)

Define a new operator that can be used as part of an OperatorMethodCombination. See examples below for more details.

Define a new operator that can be used as part of an `OperatorMethodCombination`. See examples below for more
details.
raw docstring

operatorcljmultimethod

(operator operator-name)

Define a new operator that can be used as part of an OperatorMethodCombination. See examples below for more details. Prefer using the defoperator macro to adding a method to this directly.

Define a new operator that can be used as part of an `OperatorMethodCombination`. See examples below for more
details. Prefer using the `defoperator` macro to adding a method to this directly.
raw docstring

operator-method-combinationclj

(operator-method-combination operator-name)

Create a new method combination using the operator named by operator-name, a keyword name of one of the defoperator forms above or defined externallly.

(operator-method-combination :max)

Create a new method combination using the operator named by `operator-name`, a keyword name of one of the
`defoperator` forms above or defined externallly.

  (operator-method-combination :max)
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close