r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3]

Sunanda
10-Mar-2010
[1494x2]
Raising again the now popular subject of error handling, I'd've thought 
this line of code should always print 'true....
    attempt [do "while [] []"] print 'true

....after all, it has no explicit 'RETURNs or 'BREAKs etc. It's just 
a bit  of unarguably bad code wrapped in an ATTEMPT.

(Not sure if this is a new test case, or (to Brian) an obvious application 
of the known issues; I think of it as a bug:)
And, on the same topic. R2 and R3 have divergent opinions on how 
to handle this line....
    while [return 55][print 1]
....Neither of them convincing me that they are right.
Steeve
10-Mar-2010
[1496]
It  fails in the intrinsic part of DO, I guess  (which is a mezz).
And as we know well, Mezz can't have [throw] attribute currently
BrianH
10-Mar-2010
[1497x6]
Gabriele, I don't think that, which is why I recommended that it 
be declared not a bug. I was just surprised. I do think that unwinds 
should not be assignable though, as that is a security hole and part 
of a greater problem with their operation.
Sunanda, we can't block non-trivial bad code without semantic analysis, 
which would have to include consideration of the programmer's intentions, 
which the interpreter *can't know*. And blocking trivial bad code 
would require similar analysis, but would not be worth the effort 
because people don't write trivial code.
And the while [return 55][print 1] behavior is because of bug#1509, 
it's not intentional.
Steeve, the intrinsic part of DO isn't called by DO block!, just 
by DO string!, DO file! or DO url!.
Sunanda, we only have your word for it that do "while [] []" is bad 
code. You have done nothing to tell the interpreter that it is bad, 
and other programmers might be doing it on purpose. The interpreter 
can't tell the difference: It's all in your head. That's not an insult, 
it's an unresolvable communication problem between your intentions 
and the interpreter. The interpreter has to take you at your word, 
what you said to it is do "while [] []". Which it can, so it will.
R3 isn't psychic. Anyone want to write an extension for that? Maxim? 
:)
Steeve
11-Mar-2010
[1503]
I'm well aware of this, Brian :)
>> attempt [do "while [] []"] print 'true

And if i can trust my eyes,   it''s a DO string! in Sunanda's example
Sunanda
11-Mar-2010
[1504]
Not just my word. Brian. If I type....
  do "while [] []"

..... in the console (R2 or R3), the _console_ tells me it is bad 
code.


Now, without wanting to reopen all the dicussion that has gone before, 
at the very least, this establishes that the console is not (in some 
cases) a good guide to how a line of code will be interpreted in 
a larger script.


Which goes against the traditional advice that the console is your 
friend -- such as offered here:
   http://www.rebol.org/ml-display-message.r?m=rmlMGGC
Ladislav
11-Mar-2010
[1505x3]
right, Sunanda, I guess, that this is related to CC #851
(and that it has to be corrected)
Re the while [return 55][print 1] behaviour in R2 - that is clearly 
caused by the fact, that the COND-BLOCK is (esp. in R2) handled differently 
than the BODY-BLOCK; the behaviour of UNTIL looks OK in R2
BrianH
11-Mar-2010
[1508]
Steeve, I thought you were talking about the while [return 55][print 
1] code, which would be affected by the [throw] attribute because 
it has a return in it. The attempt [do "while [] []"] print 'true 
does get processed by the intrinsic, but doesn't fail (it works correctly) 
and wouldn't be affected by [throw] because it doesn't have a return 
in it.
Steeve
11-Mar-2010
[1509]
Then, how do you explain this ?

>> attempt [do "while [][]"]
** Script error: block did not return a value
** Where: while catch either applier do attempt
** Near: while [] []

>> attempt [do [while [][]]]
== none
BrianH
11-Mar-2010
[1510x2]
Sunanda, whoops, you meant the TRY [CATCH/QUIT [...]] bug. It's already 
been reported.
Ladislav mentioned it: #851.
Steeve
11-Mar-2010
[1512]
Well, it's comming from the intrinsic part still :)
BrianH
11-Mar-2010
[1513x2]
Right. I just thought that you were talking about his other code 
because of the return. Interestingly, while [return 55][print 1] 
is buggy in both R2 and R3, but the bugs are different.
Sunanda, it turns out that the while [return 55][print 1] bug hasn't 
been reported yet. It's related to bug#1509, but not quite the same 
thing. I'll report it later today.
Sunanda
11-Mar-2010
[1515x2]
Thanks, Brian.....
.....Sounds like it needs a RAMBO and a CC report :)
BrianH
11-Mar-2010
[1517]
If it's not in the RAMBO records when they get migrated to CureCode, 
I'll submit it.
Ladislav
12-Mar-2010
[1518x2]
Sunanda/Andreas/BrianH: check my comment to the CC #1506 containing 
a B-CATCH/B-THROW example of a dynamic construct allowing an "in 
time detection" of unhandled throw
I am curious, how many users actually use the named Throw?
Pekr
12-Mar-2010
[1520]
what is there to throw? :-) ..... hence -1 :-)
Andreas
12-Mar-2010
[1521x5]
Ladislav: very nice
It's always good to see how easily we can emulate changes of internals 
at the REBOL level
I think `:result` should be `get/any 'result`, though
And named throw/catch should be easy to add as well, by just keeping 
a "stack" of handled names
A suggestion: http://bolka.at/share/bug1506-throw.r[temporary URL]
Ladislav
12-Mar-2010
[1526]
just a side note: I do not like named throws, because they can be 
caught by unnamed Catch, but not rethrown from it (the name is unavailable)
Andreas
12-Mar-2010
[1527]
Ah, yes. I don't like that as well, so of course I forgot about it.
Ladislav
12-Mar-2010
[1528]
:result versus get/any 'result - these are equivalent in R3
Andreas
12-Mar-2010
[1529x3]
Must have tested it with R2, then.
Ok, updated the script so that unnamed catch catches named throws:
b-catch [b-throw/name 42 'foo] ; == 42
Ladislav
12-Mar-2010
[1532x2]
but, anyway, when we are at discussing it, isn't there a proposal 
to improve the named throw behaviour?
Is it supposed to actually "emulate" a definitionally scoped catch/throw?
Andreas
12-Mar-2010
[1534]
Named catch/throw, you mean?
Ladislav
12-Mar-2010
[1535]
yes
Andreas
12-Mar-2010
[1536]
I'm not sure.
Ladislav
12-Mar-2010
[1537]
Nevertheless, my guess is, that:
1) named throw is not used by Rebol users
2) it can be safely discarded therefore
Andreas
12-Mar-2010
[1538x2]
Yes, it actually seems to be that way.
I grepped through the R2/R3 mezzanines and some library scripts, 
and this seems to confirm your guess.
Ladislav
12-Mar-2010
[1540]
will post that to the blog too
Andreas
12-Mar-2010
[1541x3]
I think it actually Boils down to the question what the named catch/throw 
is or should actually
.. be used for.
Is used for: not much. Should be used for: not much as well, as I 
think we could have better solutions for most error handling scenarios.