From f51e7f910d7b77801094d3de0e6917560554f1ac Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 14 Sep 2016 06:48:35 -0700 Subject: New place-mutating macro: upd. * lisplib.c (place_set_entries): Add upd to the auto-load list for place.tl. * share/txr/stdlib/place.tl (upd): New macro. * txr.1: Documented. --- lisplib.c | 2 +- share/txr/stdlib/place.tl | 5 +++++ txr.1 | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lisplib.c b/lisplib.c index e1b2a9ca..e74c925e 100644 --- a/lisplib.c +++ b/lisplib.c @@ -69,7 +69,7 @@ static val place_set_entries(val dlt, val fun) lit("with-delete-expander"), lit("set"), lit("pset"), lit("zap"), lit("flip"), lit("inc"), lit("dec"), lit("push"), lit("pop"), lit("swap"), lit("shift"), lit("rotate"), - lit("pushnew"), lit("del"), lit("lset"), + lit("pushnew"), lit("del"), lit("lset"), lit("upd"), lit("defplace"), lit("define-place-macro"), lit("define-modify-macro"), lit("placelet"), lit("placelet*"), lit("define-acessor"), lit("with-slots"), diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index d580d91a..61654509 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -371,6 +371,11 @@ places)) ,orig))) +(defmacro upd (place . opip-args) + (with-gensyms (pl) + ^(placelet ((,pl ,place)) + (set ,pl (call (opip ,*opip-args) ,pl))))) + (defmacro defplace (place-destructuring-args body-sym (getter-sym setter-sym update-body) : ((ssetter-sym clobber-body)) diff --git a/txr.1 b/txr.1 index 615ae663..47a4f0aa 100644 --- a/txr.1 +++ b/txr.1 @@ -11374,6 +11374,14 @@ Sets multiple places to values obtained from successive elements of .metn sequence . +.meIP (upd < place << opip-arg *) +Applies an +.codn opip -style +operational pipeline to the value of +.meta place +and stores the result back into +.metn place . + .PP .SS* Namespaces and Environments @@ -26545,6 +26553,32 @@ form produces the value of .meta sequence-expr as its result value. +.coNP Macro @ upd +.synb +.mets (upd < place << opip-arg *) +.syne +.desc +The +.code upd +macro evaluates +.meta place +and passes the value as an argument to the operational pipeline +function formed, +as if by the +.code opip +macro, from the +.meta opip-arg +arguments. The result of this function is then stored back into +.metn place . + +The following equivalence holds, except that place +.code p +is evaluated only once: + +.cblk + (upd p x y z ...) <--> (set p (call (opip x y z ...) p)) +.cble + .SS* User-Defined Places and Place Operators \*(TL provides a number of place-modifying operators such as .codn set , -- cgit v1.2.3