-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose.lisp
81 lines (66 loc) · 2.36 KB
/
compose.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;;; :FILE mon-systems/compose.lisp
;;; ==============================
(in-package #:mon)
;; *package*
;;; ==============================
;;; :COMPOSE-MACROS
;;; ==============================
;; :SOURCE CLOCC/cllib/port/ext.lisp
(defun compose-fun (&rest functions)
(reduce #'(lambda (f0 f1)
(declare (function f0 f1))
(lambda (&rest args) (funcall f0 (apply f1 args))))
functions :initial-value #'identity))
;; :SOURCE CLOCC/cllib/port/ext.lisp
(defun compose-all (&rest functions)
(reduce #'(lambda (f0 f1)
(declare (function f0 f1))
(lambda (&rest args)
(multiple-value-call f0 (apply f1 args))))
functions :initial-value #'identity))
;;; ==============================
;; :SOURCE CLOCC/cllib/port/ext.lisp
;; (defmacro compose-safe (&rest functions)
;; (labels ((rec (xx yy)
;; (let* ((first (first xx)) (rest (rest xx))
;; (var (gensym (format nil "~S ~S " 'compose-safe- first))))
;; (if rest
;; `(let ((,var ,(rec rest yy))) (and ,var (,first ,var)))
;; `(and ,yy (,first ,yy))))))
;; ;; #-sbcl ((with-gensyms "-COMPOSE-SAFE-" arg)
;; (with-gensyms (compose-safe-) ;;arg)
;; `(lambda (,arg) ,(rec functions arg)))))
;;
;; (setf (documentation 'compose-safe 'function)
;; #.(format nil
;; "Like `compose' but return nil when an intermediate value is nil.~%~@
;; :EXAMPLE~%~%~@
;; { ... <EXAMPLE> ... } ~%~@
;; :SEE-ALSO `compose-fun', `compose-all'.~%▶▶▶"))
;;
;;; ==============================
;;; ==============================
;;; :COMPOSE-DOCUMENTATION
;;; ==============================
(fundoc 'compose-fun
"Return the composition of all the arguments.~%~@
All FUNCTIONS should take one argument, except for the last one, which can take
several.~%~@
:EXAMPLE~%~@
{ ... <EXAMPLE> ... } ~%~@
:SEE-ALSO `compose-fun', `compose-all', `%compose'.~%▶▶▶")
(fundoc 'compose-all
"Return the composition of all the arguments.~%~@
All the values from nth function are fed to the n-1th of FUNCTIONS.~%~@
:EXAMPLE~%~@
{ ... <EXAMPLE> ... } ~%~@
:SEE-ALSO `compose-fun', `compose-all', `%compose'.~%▶▶▶")
;;; ==============================
;; Local Variables:
;; indent-tabs-mode: nil
;; show-trailing-whitespace: t
;; mode: lisp-interaction
;; package: mon
;; End:
;;; ==============================
;;; EOF