diff options
-rw-r--r-- | lisplib.c | 2 | ||||
-rw-r--r-- | share/txr/stdlib/op.tl | 3 | ||||
-rw-r--r-- | txr.1 | 38 |
3 files changed, 42 insertions, 1 deletions
@@ -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))) @@ -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 +) |