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 bdcdf80..cb6f0cc 100644 (file)
 ;;; 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
   (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.