Skip to content

Commit 0612b72

Browse files
committed
FIX: making FORALL behavior compatible with Rebol2 and Red
It looks that someone tried to always reset series position which is processed in `forall` loop. But it was not working consistently as is described in metaeducation/rebol-issues#2331 Hard to say if it was really Carl, because he would probably not write the removed comment.
1 parent a0f697c commit 0612b72

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/core/n-loop.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@
267267
}
268268
else Trap_Arg(var);
269269

270-
// !!!!! ???? allowed to write VAR????
271-
*var = *DS_ARG(1);
272-
270+
*D_RET = *var;
273271
return R_RET;
274272
}
275273

src/mezz/base-funcs.r

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ cause-error: func [
101101
change/only args spec-of first args
102102
]
103103
]
104+
args: head args
104105
; Build and throw the error:
105106
do make error! [
106107
type: err-type

src/tests/units/series-test.r3

+31
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,35 @@ Rebol [
108108
subs: ["1" "foo" "10" "bar"]
109109
--assert "bar" = reword/escape "$<10>" subs ["$<" ">"]
110110

111+
===end-group===
112+
113+
===start-group=== "FORALL"
114+
115+
--test-- "Basic FORALL"
116+
;-- compatible with R2 & Red - the series is at its tail
117+
data: [1 2 3 4]
118+
--assert unset? forall data []
119+
--assert tail? data
120+
121+
;@@ https://github.com/rebol/rebol-issues/issues/2331
122+
--test-- "Escaping from FORALL loop using THROW"
123+
data: [1 2 3 4]
124+
--assert "yes" = catch [forall data [if data/1 = 3 [throw "yes"]]]
125+
--assert [3 4] = data
126+
--test-- "Escaping from FORALL loop using BREAK"
127+
data: [1 2 3 4]
128+
--assert unset? forall data [if data/1 = 3 [break]]
129+
--assert [3 4] = data
130+
--test-- "Escaping from FORALL loop using BREAK/RETURN"
131+
data: [1 2 3 4]
132+
--assert forall data [if data/1 = 3 [break/return true]]
133+
--assert [3 4] = data
134+
--test-- "Escaping from FORALL loop on error"
135+
data: [1 2 3 4]
136+
--assert error? try [forall data [if data/1 = 3 [do make error! "stopped"]]]
137+
--assert [3 4] = data
138+
139+
===end-group===
140+
141+
111142
~~~end-file~~~

0 commit comments

Comments
 (0)