diff options
-rw-r--r-- | lisplib.c | 2 | ||||
-rw-r--r-- | share/txr/stdlib/defset.tl | 15 | ||||
-rw-r--r-- | txr.1 | 95 |
3 files changed, 107 insertions, 5 deletions
@@ -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)))) @@ -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 ]]) |