Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Rebol new-line? treat the newline keyword and the newline character similarly?

I would think that the following Rebol 3 code:

x: [newline 1 2]
y: [
1 2]

print x
print new-line? x
print y
print new-line? y

should output:

<empty line>
1 2
true
<empty line>
1 2
true

but what is output is:

<empty line>
1 2
false
1 2
true

Both blocks, when reduced, should yield a newline character followed by '1' and '2' and so, IMO, should print identically. Less clear is whether new-line? on the two blocks should also give the same result since the newline keyword should be equivalent to the literal newline for this kind of test.

like image 539
Adrian Avatar asked Jan 23 '13 09:01

Adrian


1 Answers

The flag which is checked by new-line? and set by new-line is used only by LOAD and MOLD. For all other semantic purposes in the program, it might as well not be there.

Therefore your x and y are completely different. Note that:

x: [newline 1 2]
y: [
1 2]

3 = length? x
2 = length? y

It's a quirk of Rebol that it singles out this one bit of whitespace information to stow in a hidden place. But arguably the choice to break a line represents something that is often significant in source, that if you reflect it back out into text you'd like to preserve more than the rest of the whitespace.

like image 155
HostileFork says dont trust SE Avatar answered Sep 30 '22 11:09

HostileFork says dont trust SE