summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stdlib/place.tl16
-rw-r--r--tests/012/seq.tl6
-rw-r--r--txr.1163
3 files changed, 100 insertions, 85 deletions
diff --git a/stdlib/place.tl b/stdlib/place.tl
index fba9a8d6..866e087f 100644
--- a/stdlib/place.tl
+++ b/stdlib/place.tl
@@ -601,13 +601,15 @@
(deleter
(with-gensyms (seq-sym ind-sym)
(ignore args)
- ^(alet ((,seq-sym ,seq)
- (,ind-sym ,index))
- (macrolet ((,deleter ()
- ^(prog1 (ref ,',seq-sym ,',ind-sym)
- (replace ,',seq-sym nil
- ,',ind-sym (succ ,',ind-sym)))))
- ,body)))))
+ (with-clobber-expander (seq-ssetter) seq sys:*pl-env*
+ ^(alet ((,seq-sym ,seq)
+ (,ind-sym ,index))
+ (macrolet ((,deleter ()
+ ^(prog1 (ref ,',seq-sym ,',ind-sym)
+ (,',seq-ssetter (replace ,',seq-sym nil
+ ,',ind-sym
+ (succ ,',ind-sym))))))
+ ,body))))))
(defplace (sub seq : (from 0) (to t)) body
(getter setter
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index 4b84787d..28186dbb 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -665,3 +665,9 @@
(length-< #() 1) t
(length-< #(a) 1) nil
(length-< #(a) 2) t)
+
+(let ((l (list 1 2 3 4)))
+ (del (ref l 1))
+ (test l (1 3 4))
+ (del (second l))
+ (test l (1 4)))
diff --git a/txr.1 b/txr.1
index 12cbf370..18011ce5 100644
--- a/txr.1
+++ b/txr.1
@@ -35302,21 +35302,22 @@ would return for the same arguments, and the last element is what
.code rsearch
would return.
-.coNP Functions @ ref and @ refset
+.coNP Accessor @ ref
.synb
.mets (ref < sequence << index )
-.mets (refset < sequence < index << new-value )
+.mets (set (ref < sequence << index ) << new-value )
.syne
.desc
The
.code ref
-and
-.code refset
-functions perform array-like indexing into sequences, as well as
-objects of type
-.code buf
-and
-.codn carray .
+accessor performs array-like indexing into sequences, as well as
+hash tables and objects of type
+.codn buf ,
+.codn carray ,
+.code tree
+as well as structure objects which define a
+.code lambda
+method.
If the
.meta sequence
@@ -35346,41 +35347,6 @@ treats it as a list, traversing the structure using
operations. In the absence of support for these operations,
the function fails with an error exception.
-Similarly, a structure supports
-.code refset
-directly if it has a
-.code lambda-set
-method. This gets called with
-.meta index
-and
-.meta new-value
-as arguments. Then
-.meta new-value
-is returned.
-If a structure lacks a
-.code lambda-set
-method, then
-.code refset
-treats it as a list, traversing the structure using
-.cod3 car / cdr
-operations, and storing
-.meta new-value
-using
-.codn rplaca .
-In the absence of support for these operations,
-the function fails with an error exception.
-
-The
-.code ref
-function retrieves an element of
-.metn sequence ,
-whereas
-.code refset
-overwrites an
-element of
-.meta sequence
-with a new value.
-
If
.meta sequence
is a sequence then
@@ -35412,51 +35378,92 @@ is a search tree, then
.code ref
behaves like
.codn tree-lookup .
-The
-.code refset
-function is not supported by search trees.
-The
+A
+.code ref
+expression may be used as a place. Storing a value into a
+.code ref
+place is performed using the
.code refset
-function is strict for out-of-range indices over all sequences,
-including lists. In the case of hashes, a
+function.
+
+When the
+.code del
+operator is used to delete an index value from a
+.code ref
+place, the
+.meta sequence
+itself must be a place. The deletion calculates a new
+sequence with the item at
+.meta index
+deleted; that new sequence is stored back into the
+.meta sequence
+place. Deletion does not use
.code refset
-of a nonexistent key creates the key.
+but rather the
+.code replace
+function.
+.coNP Function @ refset
+.synb
+.mets (refset < sequence < index << new-value )
+.syne
+.desc
The
.code refset
-function returns
-.codn new-value .
-
-The following equivalences hold between
-.code ref
-and
-.codn refset ,
-and the DWIM bracket syntax, provided that
-.meta idx
-is a scalar index and
+function performs indexing into
.meta sequence
-is a sequence object, rather than a hash.
-
-.verb
- (ref seq idx) <--> [seq idx]
+in a manner identical to
+.code ref
+with the purpose of overwriting the indexed element with
+.metn new-value .
+It is a companion function to
+.code ref
+which is used in the implementation of the
+.code ref
+place.
- (refset seq idx new) <--> (set [seq idx] new)
-.brev
+The return value of
+.code ref-set
+is
+.metn new-value .
-The difference is that
-.code ref
-and
+If
+.meta sequence
+is a structure, it supports
.code refset
-are first class functions which
-can be used in functional programming as higher order functions, whereas the
-bracket notation is syntactic sugar, and
-.code set
-is an operator, not a function.
-Therefore the brackets cannot replace all uses of
-.code ref
+directly if it has a
+.code lambda-set
+method. This gets called with
+.meta index
and
-.codn refset .
+.meta new-value
+as arguments. Then
+.meta new-value
+is returned.
+If a structure lacks a
+.code lambda-set
+method, then
+.code refset
+treats it as a list, traversing the structure using
+.cod3 car / cdr
+operations, and storing
+.meta new-value
+using
+.codn rplaca .
+In the absence of support for these operations,
+the function fails with an error exception.
+
+The
+.code refset
+function is not supported by search trees.
+
+The
+.code refset
+function is strict for out-of-range indices over all sequences,
+including lists. In the case of hashes, a
+.code refset
+of a nonexistent key creates the key.
.coNP Function @ update
.synb