From 4f32b4b14f5986447dc3b732b101916412c91d22 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 17 Jun 2019 07:24:00 -0700 Subject: buffers: sub-buf becomes accessor. * lisplib.c (ffi_set_entries): Register autoload for sub-buf symbol. * share/txr/stdlib/ffi.tl (sub-buf): Syntactic place defined via defset. * txr.1: Updated sub-buf documentation. --- lisplib.c | 2 +- share/txr/stdlib/ffi.tl | 3 +++ txr.1 | 18 +++++++++++++++++- 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 ]]) -- cgit v1.2.3