chiark / gitweb /
src/utilities.lisp (compose): Handle the case of zero arguments.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 3 Aug 2019 22:34:59 +0000 (23:34 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Aug 2019 22:36:06 +0000 (23:36 +0100)
src/utilities.lisp

index bdcdf80f9f4076c027531582994b5102570b7b25..cb6f0ccba742b4f96afd81b86461587736877ffc 100644 (file)
@@ -843,7 +843,7 @@ (defun backtrack-position (char line column)
 ;;; Functions.
 
 (export 'compose)
-(defun compose (function &rest more-functions)
+(defun compose (&rest functions)
   "Composition of functions.  Functions are applied left-to-right.
 
    This is the reverse order of the usual mathematical notation, but I find
@@ -854,7 +854,9 @@ (defun compose (function &rest more-functions)
   (labels ((compose1 (func-a func-b)
             (lambda (&rest args)
               (multiple-value-call func-b (apply func-a args)))))
-    (reduce #'compose1 more-functions :initial-value function)))
+    (if (null functions) #'values
+       (reduce #'compose1 (cdr functions)
+               :initial-value (car functions)))))
 
 ;;;--------------------------------------------------------------------------
 ;;; Variables.