diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-11-11 22:00:41 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-11-11 22:00:41 -0800 |
commit | 25cf62c79c1cc0438636c5d0f16eef4294b1b279 (patch) | |
tree | c7705dd79e3860f95c0e0330f482eb6aaa278934 /stdlib | |
parent | 7215b52357ee6cff03ea6c52a2c58f4f21f05add (diff) | |
download | txr-25cf62c79c1cc0438636c5d0f16eef4294b1b279.tar.gz txr-25cf62c79c1cc0438636c5d0f16eef4294b1b279.tar.bz2 txr-25cf62c79c1cc0438636c5d0f16eef4294b1b279.zip |
ref: bugfix in deletion of ref place.
The ref function is not defined in the documentation
as an accessor, but there is a ref place. Unfortunately,
deletion is broken: (del (ref x y)) does not store the
new sequence back into place x, and so it does not work
correctly for lists; if x is a list, it doesn't change.
Various accessors are defined in terms of ref, as place
macros, such as the first, second, third, ... accessors.
This fixes the bug for them also; (del (second list))
must update list.
* stdlib/place.tl (ref): Fix the delete-expander to
fetch the clobber expander of the sequence place,
and use the simple setter to put the edited sequence into
that place.
* tests/012/seq.tl: Test case, which breaks without
this fix. Test the (second ...) place also, which is defined
in terms of ref.
* txr.1: Split documentation for ref and refset, mainly
because one is an Accessor and one is a Function. Removing
some discussions about the equivalences between DWIM brackets
and ref; there are subtleties there not worth going into.
Description of refset is simplified. We mention the possibility
of del over a ref place; only in that case is the sequence
itself required to be a place.
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/place.tl | 16 |
1 files changed, 9 insertions, 7 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 |