From 14c6036dec37ae37cc0207aff130128528be7d00 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 23 Oct 2019 22:34:53 -0700 Subject: New macro: ldo. This is a left-argument-inserting syntactic sugar for do. * lisplib.c (op_set_entries): Add auto-load entry for ldo. * share/txr/stdlib/op.tl (ldo): New macro. * txr.1: Documented. --- lisplib.c | 2 +- share/txr/stdlib/op.tl | 3 +++ txr.1 | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lisplib.c b/lisplib.c index 62b41b3b..e3487496 100644 --- a/lisplib.c +++ b/lisplib.c @@ -747,7 +747,7 @@ static val debugger_set_entries(val dlt, val fun) static val op_set_entries(val dlt, val fun) { val name[] = { - lit("op"), lit("do"), lit("lop"), lit("ap"), lit("ip"), + lit("op"), lit("do"), lit("lop"), lit("ldo"), lit("ap"), lit("ip"), lit("ado"), lit("ido"), lit("ret"), lit("aret"), lit("opip"), lit("oand"), nil diff --git a/share/txr/stdlib/op.tl b/share/txr/stdlib/op.tl index ca09e49a..ac09f6df 100644 --- a/share/txr/stdlib/op.tl +++ b/share/txr/stdlib/op.tl @@ -159,6 +159,9 @@ (defmacro lop (:form f :env e . args) (sys:op-expand f e args)) +(defmacro ldo (op . args) + ^(do ,op @1 ,*args)) + (defmacro ap (. args) ^(apf (op ,*args))) diff --git a/txr.1 b/txr.1 index b560472e..836c7275 100644 --- a/txr.1 +++ b/txr.1 @@ -46466,6 +46466,44 @@ are replaced with hygienic, unique symbols. .brev +.coNP Macro @ ldo +.synb +.mets (ldo < oper << form *) +.syne +.desc +The +.code ldo +macro provides a shorthand notation for uses of the +.code do +macro which inserts the first argument of the anonymous function +as the leftmost argument of the specified operator. + +The +.code ldo +syntax can be understood in terms of these equivalences: + +.verb + (ldo f) <--> (do f @1) + (ldo f x) <--> (do f @1 x) + (ldo f x y) <--> (do f @1 x y) + (ldo f x @2 y) <--> (do f @1 x @2 y) +.brev + +The implicit argument +.code @1 +is always inserted as the leftmost argument of the operator +specified by the first form. + +.TP* Example: + +.verb + ;; push elements of l1 onto l2. + (let ((l1 '(a b c)) l2) + (mapdo (ldo push l2) l1) + l2) + --> (c b a) +.brev + .coNP Macros @, ap @, ip @ ado and @ ido. .synb .mets (ap << form +) -- cgit v1.2.3