summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisplib.c2
-rw-r--r--share/txr/stdlib/ffi.tl3
-rw-r--r--txr.118
3 files changed, 21 insertions, 2 deletions
diff --git a/lisplib.c b/lisplib.c
index d2d82b84..45d24eb9 100644
--- a/lisplib.c
+++ b/lisplib.c
@@ -620,7 +620,7 @@ static val ffi_set_entries(val dlt, val fun)
lit("deffi-sym"), lit("deffi-var"), lit("typedef"), lit("sizeof"),
lit("alignof"), lit("offsetof"), lit("arraysize"), lit("elemsize"),
lit("elemtype"), lit("ffi"), lit("carray-ref"), lit("carray-sub"),
- lit("znew"),
+ lit("sub-buf"), lit("znew"),
nil
};
set_dlt_entries(dlt, name, fun);
diff --git a/share/txr/stdlib/ffi.tl b/share/txr/stdlib/ffi.tl
index 6bbd43a9..0bf111c0 100644
--- a/share/txr/stdlib/ffi.tl
+++ b/share/txr/stdlib/ffi.tl
@@ -148,6 +148,9 @@
(defset carray-sub (carray : (from 0) (to t)) items
^(progn (carray-replace ,carray ,items ,from ,to) ,items))
+(defset sub-buf (buf : (from 0) (to t)) items
+ ^(progn (replace-buf ,buf ,items ,from ,to) ,items))
+
(defmacro znew (type . pairs)
(if (oddp (length pairs))
(throwf 'eval-error "~s: slot initform arguments must occur pairwise"
diff --git a/txr.1 b/txr.1
index 7d1f534e..1147ded8 100644
--- a/txr.1
+++ b/txr.1
@@ -59655,9 +59655,10 @@ which has the same length and contents, and compares
to
.metn buf .
-.coNP Function @ sub-buf
+.coNP Accessor @ sub-buf
.synb
.mets (sub-buf < buf >> [ from <> [ to ]])
+.mets (set (sub-buf < buf >> [ from <> [ to ]]) << new-val )
.syne
.desc
The
@@ -59668,6 +59669,21 @@ function, except that the first argument must be a buffer.
The extracted sub-range of a buffer is itself a buffer object.
+If
+.code sub-buf
+is used as a syntactic place, the argument expressions
+.metn buf ,
+.metn from ,
+.meta to
+and
+.meta new-val
+are evaluated just once. The prior value, if required, is accessed by calling
+.code buf-sub
+and
+.meta new-val
+is then stored via
+.codn replace-buf .
+
.coNP Function @ replace-buf
.synb
.mets (replace-buf < buf < item-sequence >> [ from <> [ to ]])