Skip to content

Commit 2ba01ea

Browse files
committed
CHANGE: unset value in any and all is transparent now
resolves: Oldes/Rebol-issues#850 resolves: #88
1 parent 8206872 commit 2ba01ea

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/core/n-control.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,19 @@ enum {
307307
ds = 0;
308308
while (index < SERIES_TAIL(block)) {
309309
index = Do_Next(block, index, 0); // stack volatile
310+
// ignore unset result
311+
if (IS_UNSET(DS_TOP)) {
312+
DS_DROP;
313+
continue;
314+
}
310315
ds = DS_POP; // volatile stack reference
311316
if (IS_FALSE(ds)) return R_NONE;
317+
// store the value as a potencial result
318+
DS_RET_VALUE(ds);
319+
// stop precessing if the value was thrown
312320
if (THROWN(ds)) break;
313321
}
314-
if (ds == 0) return R_TRUE;
315-
return R_TOS1;
322+
return R_RET;
316323
}
317324

318325

@@ -328,6 +335,7 @@ enum {
328335
while (index < SERIES_TAIL(block)) {
329336
index = Do_Next(block, index, 0); // stack volatile
330337
ds = DS_POP; // volatile stack reference
338+
if (IS_UNSET(ds)) continue; // ignore unset result
331339
if (!IS_FALSE(ds)) return R_TOS1;
332340
}
333341
return R_NONE;

src/tests/units/conditional-test.r3

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Rebol [
1010

1111
===start-group=== "Dealing with unset! value in conditions"
1212
--test-- "any"
13-
--assert unset? any [() 2]
13+
--assert 2 = any [() 2]
1414
--assert true? any [() 2]
1515
--test-- "all"
1616
--assert true? all []
1717
--assert true? all [()]
1818
--assert 3 = all [() 1 2 3]
19-
--assert unset? all [1 ()]
19+
--assert 1 = all [1 ()]
2020
--assert 1 = if all [1 ()][1]
2121
--assert 1 = either all [()][1][2]
2222
--test-- "any and all"
@@ -25,6 +25,13 @@ Rebol [
2525
all [true x: 2 ()]
2626
][ x: 2 * x]
2727
--assert x = 4
28+
;@@ https://github.com/Oldes/Rebol3/discussions/88
29+
--assert none? any []
30+
--assert none? any [()]
31+
--assert 1 = any [() 1]
32+
--assert 1 = all [1 ()]
33+
--assert #[true] = all []
34+
--assert #[true] = all [()]
2835
===end-group===
2936

3037
===start-group=== "SWITCH"

0 commit comments

Comments
 (0)