diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 2fa078f4..1f4e0acf 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -429,9 +429,9 @@ The composed functions can take arbitrarily many arguments and returning arbitra thing (list thing))) - (defmacro imalison:compose (name &rest funcs) + (defmacro imalison:compose (&rest funcs) "Build a new function with NAME that is the composition of FUNCS." - `(defun ,name (&rest args) + `(lambda (&rest args) (imalison:compose-helper ,funcs))) (defmacro imalison:compose-helper (funcs) @@ -441,6 +441,20 @@ The composed functions can take arbitrarily many arguments and returning arbitra `(apply ,(car funcs) (imalison:make-list (imalison:compose-helper ,(cdr funcs)))))) #+END_SRC + +Here is a unary version which avoids all the calls to imalison:make-list +#+BEGIN_SRC emacs-lisp + (defmacro imalison:compose-unary (&rest funcs) + "Build a new function with NAME that is the composition of FUNCS." + `(lambda (arg) + (imalison:compose-helper-unary ,funcs))) + + (defmacro imalison:compose-helper-unary (funcs) + "Builds funcalls of FUNCS applied to the arg." + (if (equal (length funcs) 0) + 'arg + `(funcall ,(car funcs) (imalison:compose-helper-unary ,(cdr funcs))))) +#+END_SRC ** prefix-alternatives Prefix alternatives is a macro that builds a function that selects one of a collection of functions that are provided to the macro based on the value of the prefix argument. #+BEGIN_SRC emacs-lisp