chain
2025-06-22
Two chaining/piping macros, one of them `setf`ing its first argument
Upstream URL
Author
License
Chain
[in package CHAIN]
- [system] "chain"
- Version: 0.0.1
- Description: Two chaining/piping macros, one of them
setf
ing its first argument - Licence: BSD-3
- Author: Thomas Bartscher thomas-bartscher@weltraumschlangen.de
- Depends on: metabang-bind, mgl-pax
-
[macro] => ARGUMENT &BODY BODY
Thread a value through a series of transformations, where
%
represents the value of the last transformation.-
Arguments
-
argument
: Initial value or a(:var SYMBOL INITIAL-VALUE)
binding form. -
body
: Forms to apply sequentially. Each form has%
bound as an anaphoric variable bound to the return value of the previous form in the body. Each form may be:-
A regular form
-
A
(:var SYMBOL EXPR)
form to bindSYMBOL
to the result of evaluating
EXPR
- A
(lambda (X) …)
form that is called on the result of the previous form.
-
-
-
Return value
Returns the value of its last form.
- Examples
;; Basic numeric pipeline (=> 5 (* % 2) ; => 10 (1+ %)) => 11 ;; lambda form usage (=> 5 (lambda (x) ; => 8 (+ x 3)) (* % 2)) => 16 ;; :var binding (=> 5 (:var y (* % 3)) ; y = 15, % = 15 (1+ %) ; % = 16 (+ y %)) ; y + % = 15 + 16 => 31 ;; :var in argument position (=> (:var a 5) ; a = 5, % = 5 (1+ %) ; % = 6 (+ a %)) ; a + % = 5 + 6 => 11
-
-
[macro] SET=> ARGUMENT &BODY BODY
Thread the initial value of a place through transformations like in macro
=>
, and update the place with the final result.-
Arguments
-
Return value
Returns the value of its last form.
-
Side effects
Updates
PLACE
to the calculated result. -
Examples
;;; Modify a variable (let ((x 5)) (set=> x (* % 2) ; => 10 (1+ %)) ; => 11 x) => 11 ;; Using :var (defstruct box (value 0)) (let ((b (make-box :value 8))) (set=> (:var v (box-value b)) (+ % 5) ; => 13 (* v %)) ; => 8 * 13 = 104 (box-value b)) => 104
-