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

World: r3wp

[!REBOL3]

BrianH
4-Mar-2010
[1250]
It seems so. I've asked Carl to look at those tickets and chime in, 
so we'll see what he thinks.
Andreas
4-Mar-2010
[1251x2]
Great, I'd really like to see this improved, even if it's only a 
rare corner case.
That said, we can go back to the thought experiment, if you like 
:)
BrianH
4-Mar-2010
[1253]
If you want to see how weird really optimized R3 code can get, take 
a look at the source of LOAD and IMPORT - they are probably the most 
heavily optimized mezzanine functions. For the most part the rest 
of the mezzanine code is written for readability and maintainability, 
and the language optimized to make readable code fast. It's a good 
tradeoff :)
Andreas
4-Mar-2010
[1254]
I'm well aware of the value of foreign code blocks as such. The interesting 
question, I guess, is how often foreign code is used without re-binding 
it.
BrianH
4-Mar-2010
[1255]
Most of the time, actually, otherwise the BIND/copy overhead would 
make it a poor optimization.
Andreas
4-Mar-2010
[1256x4]
Optimization is only one use case, though.
Do you have a succinct example of such a use for optimization purposes?
The nice BREAK trick used in your REPLACE would mostly be unaffected 
by this change, for example.
You'd just use the function value of the (not globally bound) function 
implementing break.
BrianH
4-Mar-2010
[1260x4]
IMPORT uses code blocks as a way of reusing duplicate code, though 
it might not be affected either. And REPLACE would be affected because 
'break wouldn't be bound at the point it is used: Being in a function 
isn't enough, it's outside of the loop. BREAK is used to break out 
of loops, not functions.
That means that the BIND/copy overhead for BREAK and CONTINUE would 
happen at every call to a loop function, not just FOR, FOREACH and 
REPEAT. And 'break and 'continue would become keywords rather than 
function names, unable to be used for loop-local variables.
LOOP, WHILE, FORALL and FORSKIP don't currently have BIND/copy overhead. 
Which is why they are used a lot in R3 :)
Sorry, I don't mean to go on about that.
Andreas
4-Mar-2010
[1264x2]
Huh?
I certainly enjoyed the discussion, then :)
BrianH
4-Mar-2010
[1266]
I don't have the time now to provide examples, I'm afraid, must run 
an errand. Try it yourself and see what you find out :)
Andreas
4-Mar-2010
[1267]
Regarding the BREAK usage in REPLACE. You currently have:
    do-break: unless all [:break]
I think that would just become:
    do-break: unless all [:system/contexts/system/break]
(Or wherever the BREAK function would be stored.)
BrianH
4-Mar-2010
[1268]
Right, though somewhere else.
Andreas
4-Mar-2010
[1269]
The added BIND/copy overhead for loop functions currently not needing 
to BIND their body is certainly true. FOREVER would be another one 
of those.
BrianH
4-Mar-2010
[1270]
REMOVE-EACH and MAP-EACH already have the BIND/copy overhead though.
Andreas
4-Mar-2010
[1271x2]
As do most other loop functions, I guess (FOREACH, FOR, REPEAT, etc.).
Only verified it for FOREACH yesterday and assumed that the other 
loop functions that need binding would also copy.
BrianH
4-Mar-2010
[1273x3]
Yup. But not all loop functions need binding, only the ones with 
a lit-word argument with a doc string that says "will be local" or 
some such.
Ah, REPEAT doesn't say that. I should submit a documentation bug 
report.
But all the loop functions that take a word argument have BIND/copy 
overhead, and the rest don't.
Andreas
4-Mar-2010
[1276]
Binding: foreach, repeat, remove-each, map-each
Not binding: forever, loop, while, until, forall, forskip
Steeve
4-Mar-2010
[1277]
btw, map-each is a burden, adding blocks by default.
Should be an option:  'map-each/only' to insert blocks,
Like other actions creating blocks do.
BrianH
4-Mar-2010
[1278]
Already proposed in CureCode, and the R2 2.7.7 version does that 
already.
Gabriele
5-Mar-2010
[1279x2]
Andreas: what you ask for has been discussed extensively when R3 
was started, by me, Ladislav and Carl. There are a number of disadvantages 
to that, starting from the fact that you need to bind/copy a lot 
more than you do now (eg. inside CATCH). It would also, unfortunately, 
not work in cases like this:
f: does [throw 'something]
catch [f]
Ladislav
5-Mar-2010
[1281x5]
Andreas: "I think that RETURN, EXIT and BREAK, CONTINUE should be 
only available in their respective contexts (functions, and loops)." 
- that is what I preferred too, but Carl did not like it (binding 
takes time).
Nevertheless, at least for Return and Exist this does not look like 
an issue, since binding is likely to occur anyway in these cases
Exit is what I meant above
and, the speed difference for Return and Exit may still exist, but 
only if the respective function does not have any parameter
I think that the implementation of improved error causation as described 
by Brian in bug#1506 would be very worthwile and should be pursued.

 - again, this is a thing I discussed with Carl quite long ago, but 
 it seems, that Carl disliked the fact, that the implementation would 
 have to be more complicated, than it currently is, while the effect 
 Sunanda would like to achieve is probably achievable even now
Andreas
5-Mar-2010
[1286x2]
Do you really think it would complicate implementation much?
Thanks for your feedback, in any case.
Ladislav
5-Mar-2010
[1288]
not me, it is what Carl thinks, if I understood him well
Andreas
5-Mar-2010
[1289]
I have to confess, I'd love to read through those discussions (if 
actually were in writing :).
BrianH
5-Mar-2010
[1290]
Carl says he is going to work on the documentation about how errors 
work.
Andreas
5-Mar-2010
[1291]
I guess that means he has no intentions of improving error causation?
BrianH
5-Mar-2010
[1292]
No, it just means that he wants to start the conversation from a 
good baseline.
Andreas
5-Mar-2010
[1293]
Fair enough.
BrianH
5-Mar-2010
[1294x2]
We've been able to find out a lot from stuff posted so far and the 
scientific method though :)
I think a lot of the problems would be solved by just letting developers 
plug in their own recovery code into the console handler, and that 
would be more efficient too.
Andreas
5-Mar-2010
[1296]
Yes. Or more generally, a special CATCH version (along with a proper 
predicate) that allows us to set up our own catch-all default handler.
Gabriele
5-Mar-2010
[1297x3]
You can already have a catch-all handler:

do does [catch [attempt code]]
add a loop 1 somewhere :-)
>> do does [loop 1 [catch [attempt [1 / 0]]]]
== none
>> do does [loop 1 [catch [attempt [exit]]]] 
>> do does [loop 1 [catch [attempt [return 10]]]]
== 10
>> do does [loop 1 [catch [attempt [break]]]]    
>> do does [loop 1 [catch [attempt [break/return 10]]]]
== 10
>> do does [loop 1 [catch [attempt [throw 10]]]]       
== 10
>> do does [loop 1 [catch [attempt [throw/name 10 'something]]]]
== 10