Skip to content

Commit 942d1ae

Browse files
committed
CHANGE: renamed remove/part argument from length to range and allowed remove/part on bitset when the argument is string, binary, block or char
related to: Oldes/Rebol-issues#933
1 parent 97c54e2 commit 942d1ae

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/boot/actions.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ remove: action [
316316
{Removes element(s); returns same position.}
317317
series [series! gob! port! bitset! none! map!] {At position (modified)}
318318
/part {Removes multiple elements or to a given position}
319-
length [number! series! pair! char!]
319+
range [number! series! pair! char!]
320320
/key {Removes a key from map.}
321321
key-arg [any-type!]
322322
]

src/core/t-bitset.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,18 @@
700700
Trap_Arg(arg);
701701

702702
case A_REMOVE: // #"a" "abc" remove/key bs "abcd"
703-
if (D_REF(ARG_REMOVE_PART)) Trap0(RE_BAD_REFINES);
704-
if (!D_REF(ARG_REMOVE_KEY)) Trap0(RE_MISSING_ARG); // /key required
705-
if (Set_Bits(VAL_SERIES(value), D_ARG(ARG_REMOVE_KEY_ARG), FALSE)) break;
703+
if (D_REF(ARG_REMOVE_KEY)) {
704+
if (D_REF(ARG_REMOVE_PART))
705+
Trap0(RE_BAD_REFINES);
706+
arg = D_ARG(ARG_REMOVE_KEY_ARG);
707+
} else if (D_REF(ARG_REMOVE_PART)) {
708+
arg = D_ARG(ARG_REMOVE_RANGE);
709+
// remove/part is allowed only with block, string, binary and char
710+
if (!(IS_BLOCK(arg) || IS_STRING(arg) || IS_BINARY(arg) || IS_CHAR(arg)))
711+
Trap_Arg(arg);
712+
}
713+
else Trap0(RE_MISSING_ARG); // /key or /part is required
714+
if (Set_Bits(VAL_SERIES(value), arg, FALSE)) break;
706715
Trap_Arg(D_ARG(3));
707716

708717
case A_COPY:

src/tests/units/bitset-test.r3

+14-6
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,34 @@
211211
clear bs
212212
--assert "make bitset! #{}" = mold bs
213213

214-
--test-- "remove-1"
214+
--test-- "remove/key"
215215
;@@ https://github.com/Oldes/Rebol-wishes/issues/20
216216
bs: charset "012345789"
217217
--assert 64 = length? bs
218218
--assert "make bitset! #{000000000000FDC0}" = mold bs
219219
--assert "make bitset! #{0000000000007DC0}" = mold remove/key bs #"0"
220220
--assert "make bitset! #{0000000000003DC0}" = mold remove/key bs 49
221221
--assert "make bitset! #{0000000000000000}" = mold remove/key bs [#"2" - #"7" "8" #"9"]
222-
--test-- "remove/part invalid"
223-
--assert all [
224-
error? e: try [remove/part bs "01"]
225-
e/id = 'bad-refines
226-
]
222+
--test-- "remove/part"
223+
;@@ https://github.com/Oldes/Rebol-issues/issues/933
224+
bs: charset "012345789"
225+
--assert "make bitset! #{0000000000007DC0}" = mold remove/part bs #"0"
226+
--assert "make bitset! #{0000000000003DC0}" = mold remove/part bs "1"
227+
--assert "make bitset! #{0000000000000000}" = mold remove/part bs [#"2" - #"7" "8" #"9"]
228+
--assert all [ error? e: try [remove/part bs 1] e/id = 'invalid-arg]
229+
--assert all [ error? e: try [remove/part/key bs "01" ""] e/id = 'bad-refines]
230+
227231
--test-- "issue-1355"
228232
;@@ https://github.com/Oldes/Rebol-issues/issues/1355
229233
--assert pick charset [not "a"] #"b"
230234
--assert not pick charset [not "a"] #"a"
231235
--assert "make bitset! #{00000000000000000000000060}" = mold poke charset "a" #"b" true
232236
--assert {make bitset! [not bits #{00000000000000000000000040}]} = mold poke charset [not "a"] #"b" true
233237

238+
--test-- "issue-933"
239+
;@@ https://github.com/Oldes/Rebol-issues/issues/933
240+
--assert all [error? e: try [remove make bitset! #{FF}] e/id = 'missing-arg]
241+
234242
===end-group===
235243

236244

0 commit comments

Comments
 (0)