Skip to content

Commit cf740c4

Browse files
committed
FEAT: making UNSET! as a conditionally "TRUTHY"
related issues: metaeducation/rebol-issues#564 metaeducation/rebol-issues#850 It reverts changes discussed in above issues as I consider this behavior to be more useful and it is compatible with Rebol2 and Red. My main reason is to be able use PRINT inside ALL blocks without need to worry if these would affect the evaluation. Like in this case: ``` if all [ not headers any [ all [ d1: find conn/data crlfbin d2: find/tail d1 crlf2bin print "server using standard content separator of #{0D0A0D0A}" ] all [ d1: find conn/data #{0A} d2: find/tail d1 #{0A0A} print "server using malformed line separator of #{0A0A}" ] ] ][ ... ] ```
1 parent c5cfb69 commit cf740c4

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

src/boot/natives.r

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ do: native [
132132

133133
either: native [
134134
{If TRUE condition return first arg, else second; evaluate blocks by default.}
135-
condition
135+
condition [any-type!]
136136
true-branch
137137
false-branch
138138
/only "Suppress evaluation of block args."
@@ -188,7 +188,7 @@ halt: native [
188188

189189
if: native [
190190
{If TRUE condition, return arg; evaluate blocks by default.}
191-
condition
191+
condition [any-type!]
192192
true-branch
193193
/only "Return block arg instead of evaluating it."
194194
]
@@ -307,7 +307,7 @@ try: native [
307307

308308
unless: native [
309309
{If FALSE condition, return arg; evaluate blocks by default.}
310-
condition
310+
condition [any-type!]
311311
false-branch
312312
/only "Return block arg instead of evaluating it."
313313
]
@@ -818,7 +818,7 @@ log-e: native [
818818

819819
not: native [
820820
{Returns the logic complement.}
821-
value {(Only FALSE and NONE return TRUE)}
821+
value [any-type!] {(Only FALSE and NONE return TRUE)}
822822
]
823823

824824
square-root: native [

src/core/n-control.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ enum {
294294
while (index < SERIES_TAIL(block)) {
295295
index = Do_Next(block, index, 0); // stack volatile
296296
ds = DS_POP; // volatile stack reference
297-
if (!IS_FALSE(ds) && !IS_UNSET(ds)) return R_TOS1;
297+
if (!IS_FALSE(ds)) return R_TOS1;
298298
}
299299
return R_NONE;
300300
}

src/mezz/base-defs.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ scalar?: func [
136136

137137
true?: func [
138138
"Returns true if an expression can be used as true."
139-
val ; Note: No [any-type!] - we want unset! to fail.
139+
val [any-type!] ;- we want unset! not to fail.
140140
] [not not :val]
141141

142142
quote: func [

src/tests/run-tests.r3

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ wrap load %units/dh-test.r3
1818
wrap load %units/port-test.r3
1919
wrap load %units/checksum-test.r3
2020
wrap load %units/enum-test.r3
21+
wrap load %units/conditional-test.r3
2122

2223
wrap load %units/crash-test.r3
2324

src/tests/units/conditional-test.r3

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Rebol [
2+
Title: "Rebol conditional test script"
3+
Author: "Olds"
4+
File: %conditional-test.r3
5+
Tabs: 4
6+
Needs: [%../quick-test-module.r3]
7+
]
8+
9+
~~~start-file~~~ "Conditional"
10+
11+
===start-group=== "Dealing with unset! value in conditions"
12+
--test-- "any"
13+
--assert unset? any [() 2]
14+
--assert true? any [() 2]
15+
--test-- "all"
16+
--assert true? all []
17+
--assert true? all [()]
18+
--assert 3 = all [() 1 2 3]
19+
--assert unset? all [1 ()]
20+
--assert 1 = if all [1 ()][1]
21+
--assert 1 = either all [()][1][2]
22+
--test-- "any and all"
23+
if any [
24+
all [false x: 1 ()]
25+
all [true x: 2 ()]
26+
][ x: 2 * x]
27+
--assert x = 4
28+
29+
30+
===end-group===
31+
32+
~~~end-file~~~

0 commit comments

Comments
 (0)