From 1eb3f48dfc8945a1d6c8753c17f9700437d260e8 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Tue, 21 Jun 2016 15:54:57 -0700 Subject: [PATCH] Add a version of compose for named functions This version is interesting because it works with macros --- dotfiles/emacs.d/README.org | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 0fb3b0e8..7bbe5b76 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -468,6 +468,21 @@ Here is a unary version which avoids all the calls to imalison:make-list 'arg `(funcall ,(car funcs) (imalison:compose-helper-unary ,(cdr funcs))))) #+END_SRC + +Here is a version that will support macros and requires unary functions after the first one +#+BEGIN_SRC emacs-lisp + (defmacro imalison:compose-named-functions (arguments &rest funcs) + "Build a new function with NAME that is the composition of FUNCS." + `(lambda ,arguments + (imalison:compose-named-functions-helper ,funcs ,arguments))) + + (defmacro imalison:compose-named-functions-helper (funcs arguments) + "Builds funcalls of FUNCS applied to the arg." + (if (equal (length funcs) 1) + `(,(car funcs) ,@arguments) + `(,(car funcs) + (imalison:compose-named-functions-helper ,(cdr funcs) ,arguments)))) +#+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