Skip to content

Commit cbc7b88

Browse files
committed
FEAT: reduce paren! evaluate and generate paren!
resolves: Oldes/Rebol-issues#2060
1 parent b5fc6f2 commit cbc7b88

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/core/n-control.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ enum {
742742
REBVAL *val = D_ARG(1);
743743
REBVAL *into = D_REF(5) ? D_ARG(6) : 0;
744744

745-
if (IS_BLOCK(val)) {
745+
if (IS_BLOCK(val) || IS_PAREN(val)) {
746746
REBSER *ser = VAL_SERIES(val);
747747
REBCNT index = VAL_INDEX(val);
748748

@@ -752,6 +752,10 @@ enum {
752752
Reduce_Only(ser, index, D_ARG(4), into);
753753
else
754754
Reduce_Block(ser, index, into);
755+
756+
if(!into)
757+
SET_TYPE(DS_TOP, VAL_TYPE(val));
758+
755759
return R_TOS;
756760
}
757761
else if (into != 0) {

src/tests/units/series-test.r3

+26
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,32 @@ Rebol [
288288
===end-group===
289289

290290

291+
===start-group=== "REDUCE"
292+
--test-- "reduce block!"
293+
--assert [2 6] == reduce [1 + 1 3 + 3]
294+
--assert all [
295+
[x] == reduce/into [1 + 1 3 + 3] b: [x]
296+
b = [2 6 x]
297+
]
298+
--assert all [
299+
tail? reduce/into ['a 1 + 1 3 + 3] p: make path! 3
300+
p = 'a/2/6
301+
]
302+
--test-- "reduce paren!"
303+
;@@ https://github.com/Oldes/Rebol-issues/issues/2060
304+
--assert 2 = reduce (1 + 1)
305+
--assert quote (2 6) == reduce quote (1 + 1 3 + 3)
306+
--assert all [
307+
[x] == reduce/into quote (1 + 1 3 + 3) b: [x]
308+
b = [2 6 x]
309+
]
310+
--assert all [
311+
tail? reduce/into quote ('a 1 + 1 3 + 3) p: make path! 3
312+
p = 'a/2/6
313+
]
314+
===end-group===
315+
316+
291317
===start-group=== "TRIM"
292318
--test-- "trim string!"
293319
str1: " a b c "

0 commit comments

Comments
 (0)