REBOL3 tracker
  0.9.12 beta
Ticket #0002245 User: anonymous

Project:

Previous Next
rss
TypeBug Statusreviewed Date14-Aug-2015 01:30
Versionr3 master CategoryNative Submitted byfork
PlatformAll Severityminor Prioritynormal

Summary CASE statements don't evaluate "body" code for false "conditions"
Description Where an IF statement is laid out as:

if condition body

CASE statements are laid out roughly as:

case [
condition1 body1
condition2 body2
condition3 body3
]

The rule for CASE is that the bodies don't not need to be blocks, or evaluate to one...it can be any expression that produces a value. Moreover, if the expression evaluates to a block, it will be executed in a second evaluation step. (Behavior-wise, the updated behavior of Rebol3's IF brings it into parity.)

>> code: [print "Hello"]
>> case [true code]
Hello

There is however a problem in that Rebol's CASE (in both Rebol2 and Rebol3) only uses a DO/NEXT evaluation on the bodies inside a case if the condition is "TRUE?". This leads to a problem that the truth or falsehood of an expression can change the "shape" of the case's execution:

>> condition: true
>> case [condition 10 + 20]
== 30

>> condition: false
>> case [condition 10 + 20]
>> case [condition 10 + 20]
** Script error: cannot use add on none! value
** Where: + case
** Near: + 20

This is because false conditions skip one item. It needs to skip however many items it takes, which is what would have happened if this had been written as IF CONDITION 10 + 20.
Example code

			

Assigned ton/a Fixed in- Last Update5-Jan-2016 23:45


Comments
(0004662)
Ladislav
11-Dec-2015 14:26

The described problem exists also in Rebol 2.
(0004663)
Ladislav
11-Dec-2015 14:40

Observation:

a: 1
if false (a: 2 [a: 3])
a ; == 2

Does that mean that

a: 1
case [
false (a: 2 [a: 3])
]
a

should yield 2 too?
(0004675)
Ladislav
3-Jan-2016 21:33

This needs a more complete specification of the desired behaviour.

Date User Field Action Change
5-Jan-2016 23:45 ladislav Description Modified -
5-Jan-2016 23:45 ladislav Status Modified submitted => reviewed
3-Jan-2016 21:33 ladislav Comment : 0004675 Added -
14-Dec-2015 17:17 ladislav Comment : 0004664 Removed -
13-Dec-2015 16:18 Ladislav Comment : 0004664 Added -
13-Dec-2015 16:16 Ladislav Comment : 0004663 Modified -
11-Dec-2015 14:41 ladislav Comment : 0004663 Modified -
11-Dec-2015 14:40 ladislav Comment : 0004663 Added -
11-Dec-2015 14:29 ladislav Comment : 0004662 Modified -
11-Dec-2015 14:28 ladislav Comment : 0004662 Modified -
11-Dec-2015 14:26 ladislav Comment : 0004662 Added -
14-Aug-2015 01:30 Fork Ticket Added -