Homepage: https://github.com/ROCKTAKEY/recur
Author: ROCKTAKEY
Updated:
Tail call optimization
Tail call optimization for Emacs. `recur' means recursive call (like clojure). All `recur' must be called on tail. (recur-loop ;Same as `recur-let' ((x 5) (y 1)) (if (eq x 0) y (recur (1- x) (* x y)))) ;; => 120 (recur-progv '(x y) '(5 1) (if (eq x 0) y (recur (1- x) (* x y)))) ;; => 120 (recur-defun factorial (x &optional y) (setq y (or y 1)) (if (eq x 0) y (recur (1- x) (* x y)))) ;; => factorial (factorial 5 1) ;; => 120 (factorial 5) ;; => 120 How to Use? `recur-loop' / `recur-let' Recursively callable `let'. Similar to `loop' in clojure. This is same as `recur-progv', except using `BINDINGS' like `let' instead of `SYMBOLS' and `INITVALUES'. `BODY' is evaluated with variables set by `BINDINGS'. Note that `recur' MUST be tail recursion and this macro optimize tail call. `recur-progv' Recursively callable `cl-progv'. `SYMBOLS', `INITVALUES' (as `VALUES'), and `BODY' are same as arguments of `cl-progv'. In addition, you can use function `recur' in `BODY' form. This function take arguments same number as length of `SYMBOLS', and evaluate `BODY' form with `SYMBOLS' bounded by each value of arguments. Note that `recur' MUST be tail recursion and this macro optimize tail call. `recur-defun' Define function with tail call optimization. `NAME', `ARGLIST', `DOCSTRING' and `BODY' is same as arguments of `defun'. `recur' in `BODY' calls the function named NAME itself with arguments. `recur' cannot recieve variable length arguments, so you must pass one list even as =&rest= argument. Note that `recur' MUST be tail recursion and this macro optimize tail call. License This package is licensed by GPLv3. See LICENSE.