summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-17 23:16:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-17 23:16:22 -0700
commite545f014c3e3336c929e0981948cc8f62423be7e (patch)
tree2a36f8452dd2ab3228d0c27121fee914fed0f0b1
parent60d79d3d94445b9b27c1b394499995847e889d64 (diff)
downloadtxr-e545f014c3e3336c929e0981948cc8f62423be7e.tar.gz
txr-e545f014c3e3336c929e0981948cc8f62423be7e.tar.bz2
txr-e545f014c3e3336c929e0981948cc8f62423be7e.zip
sub-list, sub-vec, sub-str: becoming accessors.
* lisplib.c (defset_instantiate): Add sub-list, sub-vec and sub-str symbols as autoload triggers for defset.tl. * share/txr/stdlib/defset.tl (sub-list, sub-vec, sub-str): New syntactic places defined with defset. * txr.1: sub-list, sub-vec and sub-str documented as accessors.
-rw-r--r--lisplib.c2
-rw-r--r--share/txr/stdlib/defset.tl15
-rw-r--r--txr.195
3 files changed, 107 insertions, 5 deletions
diff --git a/lisplib.c b/lisplib.c
index 45d24eb9..e47bcf3a 100644
--- a/lisplib.c
+++ b/lisplib.c
@@ -787,7 +787,7 @@ static val defset_instantiate(val set_fun)
static val defset_set_entries(val dlt, val fun)
{
val name[] = {
- lit("defset"),
+ lit("defset"), lit("sub-list"), lit("sub-vec"), lit("sub-str"),
nil
};
set_dlt_entries(dlt, name, fun);
diff --git a/share/txr/stdlib/defset.tl b/share/txr/stdlib/defset.tl
index 7a2dd6fd..d666f199 100644
--- a/share/txr/stdlib/defset.tl
+++ b/share/txr/stdlib/defset.tl
@@ -105,3 +105,18 @@
((get-fun set-fun)
(defset-expander-simple mf get-fun set-fun))
(x (compile-error mf "invalid syntax"))))
+
+(defset sub-list (list : (from 0) (to t)) items
+ (let ((it (gensym)))
+ ^(alet ((,it ,items))
+ (progn (set ,list (replace-list ,list ,it ,from ,to)) ,it))))
+
+(defset sub-vec (vec : (from 0) (to t)) items
+ (let ((it (gensym)))
+ ^(alet ((,it ,items))
+ (progn (replace-vec ,vec ,it ,from ,to) ,it))))
+
+(defset sub-str (str : (from 0) (to t)) items
+ (let ((it (gensym)))
+ ^(alet ((,it ,items))
+ (progn (replace-str ,str ,it ,from ,to) ,it))))
diff --git a/txr.1 b/txr.1
index 1147ded8..ab1923d3 100644
--- a/txr.1
+++ b/txr.1
@@ -19027,9 +19027,10 @@ cannot be rewritten as
because the latter is equivalent to
.codn "(list 1 2 func 3)" .
-.coNP Function @ sub-list
+.coNP Accessor @ sub-list
.synb
.mets (sub-list < list >> [ from <> [ to ]])
+.mets (set (sub-list < list >> [ from <> [ to ]]) << new-value )
.syne
.desc
The
@@ -19043,6 +19044,36 @@ argument using list operations, and assumes that
it is terminated by
.codn nil .
+If a
+.code sub-list
+form is used as a place, then the
+.meta list
+argument form must also be a place.
+
+The
+.code sub-list
+place denotes a subrange of
+.meta list
+as if it were a storage location. The previous value of this location,
+if needed, is fetched by a call to
+.codn sub-list .
+Storing
+.meta new-value
+to the place is performed by a call to
+.codn replace-list .
+The return value of
+.meta replace-list
+is stored into
+.metn list .
+In an update operation which accesses the prior value and stores a new value,
+the arguments
+.metn list ,
+.metn from ,
+.meta to
+and
+.meta new-value
+are evaluated once.
+
.coNP Function @ replace-list
.synb
.mets (replace-list < list < item-sequence >> [ from <> [ to ]])
@@ -22014,9 +22045,10 @@ If
is a single string atom, then the function behaves
exactly like match-str.
-.coNP Function @ sub-str
+.coNP Accessor @ sub-str
.synb
-.mets (sub-str < string >> [ from <> [ to ]])
+.mets (sub-str < str >> [ from <> [ to ]])
+.mets (set (sub-str < str >> [ from <> [ to ]]) << new-value )
.syne
.desc
The
@@ -22027,6 +22059,33 @@ function,
function, except that the first argument is operated upon
using string operations.
+If a
+.code sub-str
+form is used as a place, it denotes a subrange of
+.meta list
+as if it were a storage location. The previous value of this location,
+if needed, is fetched by a call to
+.codn sub-str .
+Storing
+.meta new-value
+to the place is performed by a call to
+.codn replace-str .
+In an update operation which accesses the prior value and stores a new value,
+the arguments
+.metn str ,
+.metn from ,
+.meta to
+and
+.meta new-value
+are evaluated once.
+
+The
+.meta str
+argument is not itself required to be a place; it is not updated
+when a value is written to the
+.code sub-str
+storage location.
+
.coNP Function @ replace-str
.synb
.mets (replace-str < string < item-sequence >> [ from <> [ to ]])
@@ -23421,9 +23480,10 @@ as
.meta vec
and containing the same elements in the same order.
-.coNP Function @ sub-vec
+.coNP Accessor @ sub-vec
.synb
.mets (sub-vec < vec >> [ from <> [ to ]])
+.mets (set (sub-vec < vec >> [ from <> [ to ]]) << new-value )
.syne
.desc
The
@@ -23435,6 +23495,33 @@ except that the
.meta vec
argument must be a vector.
+If a
+.code sub-vec
+form is used as a place, it denotes a subrange of
+.meta list
+as if it were a storage location. The previous value of this location,
+if needed, is fetched by a call to
+.codn sub-vec .
+Storing
+.meta new-value
+to the place is performed by a call to
+.codn replace-vec .
+In an update operation which accesses the prior value and stores a new value,
+the arguments
+.metn vec ,
+.metn from ,
+.meta to
+and
+.meta new-value
+are evaluated once.
+
+The
+.meta vec
+argument is not itself required to be a place; it is not updated
+when a value is written to the
+.code sub-vec
+storage location.
+
.coNP Function @ replace-vec
.synb
.mets (replace-vec < vec < item-sequence >> [ from <> [ to ]])