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

World: r3wp

[!REBOL3]

Ladislav
7-Mar-2010
[1466x6]
I am not sure I understood the plan, is it so, that the plan is, 
to have two types of functions depending on an attribute:
-functions with dynamically scoped Return/Exit
-functions with definitionally scoped Return/Exit
?
BrianH, definitonally scoped Return/Exit need not be disabled, it 
would "automatically" work as expected, that is the beauty of the 
approach
(my article discussing function attributes illustrates that)
http://www.compkarori.com/vanilla/display/Function-Attributes
What's the quickest way to detect R3 vs R2 for hybrid scripts?

 - see e.g. http://www.rebol.org/art-display-article.r?article=w24v
Note to the "Should we catch unwinds?" question in the http://www.rebol.com/r3/notes/errors.html
article - the subject of the CureCode #1506 is, that it is (or should 
be) possible for the interpreter to find out, whether the unwind 
would cause a "No catch for throw" type error, and, that Try should 
catch such an "unhandled" unwind.
Gregg
7-Mar-2010
[1472]
Excellent article Ladislav. Thanks for taking the time to write that.
BrianH
7-Mar-2010
[1473x2]
I wrote a few comments to the blog, explaining the advantages of 
the definitionally scoped RETURN and EXIT proposal. The optional 
function attribute we would need would not change them to dynamically 
scoped, it would just tell the function to not redefine RETURN and 
EXIT within, allowing them to keep their existing bindings. No dynamic 
scoping of those functions would be needed at all.
Adjusted the wording of bug#1509 to reflect the new documentation 
of the unwind functions.
Geomol
8-Mar-2010
[1475]
(Continuing from "Rebol School".)


I've thought about TRY/EXCEPT too, since it popped up a few days 
ago. My thoughts are more about design. Why do we have TRY? Why not 
make /EXCEPT a refinement of DO? DO can do any type, TRY only works 
on blocks. If you wanna do a script on the net, and it can go wrong, 
we have to write:

try/except [do <url>] [<handle error>]

With /EXCEPT on DO, it could be:

do/except <url> [<handle error>]


My point is: is it good to have all these words in the language? 
It may add depth, but it also add confusion and complexity. Maybe 
the depth could still be there with fewer words, and the language 
would be easier?
Henrik
8-Mar-2010
[1476]
I don't miss a simplification of DO/TRY as much as structures for 
sequential tests that may or may not fail. REBOL doesn't have anything 
here, so you have to roll your own. Say you're trying to connect 
somewhere in a protocol and one of 50 things can go wrong, so you 
have to state 50 tests, 50 error messages, 50 exit routes. That's 
a lot of lines of almost identical code.
Geomol
8-Mar-2010
[1477x3]
There may be another concern with this. How do we get the error in 
the except block, so we can handle it? A common way is:

if error? result: try [1 / 0] [probe result]

This doesn't work:
(Remember to clear result, if you did the above first.)

result: try/except [1 / 0] [probe result]

And having /EXCEPT on DO is the same problem.
Henrik, yes, what you explain is a common problem. The best way to 
handle it, as I see it, is with a foreach loop, like this:

foreach [code handle-error] [
	[do something] [handle-error-1]
	[do something-else] [handle-error-2]
	...
] [
	if error? err: try code handle-error
]
Ah, maybe handle-error-1, -2, ... shouldn't be in blocks. But you 
get the idea.
Henrik
8-Mar-2010
[1480]
that's possible, although you need to break at the error. at least 
that's how I would want it
Geomol
8-Mar-2010
[1481x5]
Agree, gotta break out of the FOREACH loop too.
A better example of the foreach loop:

foreach [code handle] [
	[1 / 0] [print "error 1"]
	[2 / 0] [print "error 2"]
] [
	if error? try code [do handle break]
]
If last error was kept in a system variable (so we could get it there), 
the /EXCEPT refinement would make better sense.
Maybe it is in system/state/last-error
No, doesn't seem to work, if you handle the error yourself.
BrianH
8-Mar-2010
[1486]
Geomol, set-word assignment uses the SET function, which by default 
doesn't accept error! values (by design). If you want to assign error 
values then use SET/any.
Gabriele
9-Mar-2010
[1487]
Geomol, maybe you're missing that /except accepts a function, ie. 
try/except [...] func [error] [probe error]
Geomol
9-Mar-2010
[1488x2]
Gabriele, yes, I didn't see that. So it should be possible to do, 
what I considered.
Brian, no, it works here (version 2.100.95.3.1). Do this:

if error? result: try [1 / 0] [probe result]

It's unset!, SET can't set, not error!.
BrianH
9-Mar-2010
[1490x3]
Weird, that shouldn't work. That should be reported.
It looks like untriggered errors are assignable with set-words in 
R3. I wonder if that was an intentional change. It should be reported 
as a bug, with a request for Carl to say whether it was intentional.
I reported the bug in #1515, recommending that it be declared not 
a bug. However, when combined with #1509 it turns into a nasty security 
bug (similar to #1004). We really need to fix #1509 asap.
Gabriele
10-Mar-2010
[1493]
Brian, why do you think that errors should not be assignable with 
set-words?
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
[1515]
Thanks, Brian.....