Skip to content

Commit b71d816

Browse files
committed
CHANGE: allow unset none to be a no-op instead of throwing an error
implements: Oldes/Rebol-wishes#28
1 parent 97cae72 commit b71d816

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/boot/natives.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ type?: native [
594594

595595
unset: native [
596596
{Unsets the value of a word (in its current context.)}
597-
word [word! block!] {Word or block of words}
597+
word [word! block! none!] {Word or block of words}
598598
]
599599

600600
utf?: native [

src/core/n-data.c

+3
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ static int Check_Char_Range(REBVAL *val, REBINT limit)
686686
value = Get_Var(word);
687687
SET_UNSET(value);
688688
} else Trap1(RE_NOT_DEFINED, word);
689+
} else if (IS_NONE(word)) {
690+
// https://github.com/Oldes/Rebol-wishes/issues/28
691+
return R_NONE;
689692
} else {
690693
for (word = VAL_BLK_DATA(word); NOT_END(word); word++) {
691694
if (IS_WORD(word)) {

src/tests/units/object-test.r3

+18
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Rebol [
203203
--assert not same? a b
204204
===end-group===
205205

206+
206207
===start-group=== "Object actions"
207208
--test-- "empty?"
208209
;@@ https://github.com/Oldes/Rebol-issues/issues/1669
@@ -215,6 +216,23 @@ Rebol [
215216
===end-group===
216217

217218

219+
===start-group=== "UNSET in object"
220+
--test-- "unset ctx"
221+
ctx: context [a: 1 b: 2 c: 3]
222+
--assert unset? unset in ctx 'a
223+
--assert unset? unset bind [b c] ctx
224+
--assert all [
225+
unset? :ctx/a
226+
unset? :ctx/b
227+
unset? :ctx/c
228+
]
229+
;@@ https://github.com/Oldes/Rebol-wishes/issues/28
230+
--assert none? unset in ctx 'd
231+
232+
233+
===end-group===
234+
235+
218236
===start-group=== "APPEND on OBJECT"
219237
;@@ https://github.com/Oldes/Rebol-issues/issues/708
220238
--test-- "issue-708"

0 commit comments

Comments
 (0)