From 6f36fb3053770473ea7ed73fa39b775eaf195099 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 11 Sep 2016 18:42:00 -0700 Subject: New alet macro. * lisplib.c (place_set_entries): Add alet symbol to autoload list for place.tl. * share/txr/stdlib/place.tl (alet): New macro. * txr.1: Documented alet. --- lisplib.c | 2 +- share/txr/stdlib/place.tl | 6 ++++++ txr.1 | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lisplib.c b/lisplib.c index 49e4841e..e1b2a9ca 100644 --- a/lisplib.c +++ b/lisplib.c @@ -62,7 +62,7 @@ static val place_set_entries(val dlt, val fun) lit("get-update-expander"), lit("get-clobber-expander"), lit("get-delete-expander"), lit("place-form-p"), - lit("rlet"), lit("slet"), lit("with-gensyms"), + lit("rlet"), lit("slet"), lit("alet"), lit("with-gensyms"), lit("call-update-expander"), lit("call-clobber-expander"), lit("call-delete-expander)"), lit("with-update-expander"), lit("with-clobber-expander"), diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index 74b5b01d..4d5e63dd 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -133,6 +133,12 @@ (defmacro slet (bindings :env e . body) (sys:r-s-let-expander bindings body e [orf constantp bindable])) +(defmacro alet (bindings :env e . body) + (let ((exp-bindings (mapcar (aret ^(,@1 ,(macroexpand @2 e))) bindings))) + ^(,(if [all exp-bindings [orf constantp bindable] second] + 'symacrolet 'let) + ,exp-bindings ,*body))) + (defmacro with-gensyms (syms . body) ^(let ,(zip syms (repeat '((gensym)))) ,*body)) diff --git a/txr.1 b/txr.1 index d4a42a72..06d4e775 100644 --- a/txr.1 +++ b/txr.1 @@ -27812,6 +27812,31 @@ to symbol macros. In addition, unlike also reduces to symbol macros those bindings which are initialized by symbol expressions (values of variables). +.coNP Macro @ alet +.synb +.mets (alet >> ({( sym << init-form )}*) << body-form *) +.syne +.desc +The macro +.code alet +("atomic" or "all") is a stronger form of the +.code slet +macro. The transformation of any of the bindings to symbol macros takes place +under the same conditions as under +.codn slet . +However, +.code alet +imposes the restriction that all the bindings must be transformed +to symbol macros, or not at all. + +The +.code alet +macro can be used to avoid introducing temporary variables in situations when +it is suspected that the initializing forms for the variables have side +effects through which they affect each others' evaluations. The suspicion is +lifted if the all initializing forms (after expansion) are constants, or +accesses to symbols. + .coNP Macro @ define-accessor .synb .mets (define-accessor < get-function << set-function ) -- cgit v1.2.3