# HG changeset patch # User Steve Losh # Date 1506386830 14400 # Node ID 126034bff1da31e7d291cdad5f1d835b351b0781 # Parent 7528d18f2430b7513c426bd90d0a0e3b607a5b73 Add Fare's `nest` macro diff -r 7528d18f2430 -r 126034bff1da losh.lisp --- a/losh.lisp Wed Aug 09 14:55:32 2017 -0400 +++ b/losh.lisp Mon Sep 25 20:47:10 2017 -0400 @@ -14,6 +14,30 @@ forms)) <>)) +(defmacro nest (&rest forms) + "Thread the given forms, putting each as the body of the previous. + + Example: + + (nest (multiple-value-bind (a b c) (foo)) + (when (and a b c)) + (multiple-value-bind (d e f) (bar)) + (when (and d e f)) + (do-something)) + + macroexpands to: + + (multiple-value-bind (a b c) (foo) + (when (and a b c) + (multiple-value-bind (d e f) (bar) + (when (and d e f) + (do-something))))) + + " + ;; thanks, Fare + (reduce (lambda (prefix body) `(,@prefix ,body)) + forms :from-end t)) + ;;;; Types -------------------------------------------------------------------- (deftype array-index (&optional (length (1- array-dimension-limit))) diff -r 7528d18f2430 -r 126034bff1da package.lisp --- a/package.lisp Wed Aug 09 14:55:32 2017 -0400 +++ b/package.lisp Mon Sep 25 20:47:10 2017 -0400 @@ -62,6 +62,7 @@ (:export :-<> :<> + :nest :recursively :recur :when-found