summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-10-23 22:34:53 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-10-23 22:34:53 -0700
commit14c6036dec37ae37cc0207aff130128528be7d00 (patch)
treebb33ffd59940873e9f4d1ba68f0d88d1828a1f35
parent718995e74b8446d5cc66b3592efcf69e0c24133d (diff)
downloadtxr-14c6036dec37ae37cc0207aff130128528be7d00.tar.gz
txr-14c6036dec37ae37cc0207aff130128528be7d00.tar.bz2
txr-14c6036dec37ae37cc0207aff130128528be7d00.zip
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.
-rw-r--r--lisplib.c2
-rw-r--r--share/txr/stdlib/op.tl3
-rw-r--r--txr.138
3 files changed, 42 insertions, 1 deletions
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 +)