From 7e13bb4e5f142d2fbfaa03f88ba1263978adc930 Mon Sep 17 00:00:00 2001 From: Matthew Egan Odendahl Date: Fri, 15 Apr 2016 20:33:42 -0600 Subject: [PATCH] add as-> macro --- hy/core/macros.hy | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hy/core/macros.hy b/hy/core/macros.hy index d39aabe..dc3c316 100644 --- a/hy/core/macros.hy +++ b/hy/core/macros.hy @@ -30,6 +30,15 @@ [hy.models.symbol [HySymbol]] [hy._compat [PY33 PY34]]) +(defmacro as-> [head name &rest rest] + "Becomes ordered assignments to the provided name. The previous result + is thus available in each form. Returns the final result, and leaves the name + bound to it in the local scope. This behaves like the threading macros, but + requires you to specify the threading point per form via the name." + `(do (setv + ~name ~head + ~@(interleave (repeat name) rest)) + ~name)) (defmacro with [args &rest body] "shorthand for nested with* loops: