World: r3wp
[Core] Discuss core issues
older newer | first last |
Ladislav 2-Nov-2010 [296] | Another potentially useful function: CATCH-ANY. Can be found at: http://github.com/rebolsource/rebol-test as well. |
BrianH 2-Nov-2010 [297] | Post it to the idioms group in R3 chat #754, either the file, a link to the original, or as source in a message. |
Ladislav 3-Nov-2010 [298x3] | The CATCH-ANY function above catches almost all REBOL exceptions. One that it does not catch is HALT. Is HALT meant to be "uncatchable", or not? |
(shall this question be CureCoded?) | |
My preferences are, that HALT should be catchable, since that would allow us to e.g. write a REBOL console in View. | |
Maxim 3-Nov-2010 [301] | catch halt could be a nice wish |
Ladislav 3-Nov-2010 [302x2] | Done |
Examining the core-tests suite results I wonder, which alternative do you prefer: a: >> for i 1 3 1 [print i if i = 1 [i: 2]] 1 2 3 == none b: >> for i 1 3 1 [print i if i = 1 [i: 2]] 1 3 == none | |
GrahamC 3-Nov-2010 [304x6] | latter |
it's like a loop | |
sort of | |
actually that's a construct I miss.... eg. in dbase we had do loop [ ............ ] endloop or something like that. but you could exit anyway inside that block to restart the loop like this do loop [ .... loop .... ] endloop | |
we only have break which exists a loop | |
exits | |
Sunanda 3-Nov-2010 [310x2] | You can do it with an idiomatic use of LOOP 1 [...] But that loses an easy way to use BREAK for real. for n 1 5 1 [ loop 1 [ if n < 3 [break] print n ] ] |
R3 has CONTINUE for n 1 5 1 [ if n < 3 [continue] print n ] | |
GrahamC 3-Nov-2010 [312] | need a break^2 |
Ladislav 3-Nov-2010 [313] | you mean for this?: for n 1 5 1 [ catch/name [ if n < 3 [throw/name none 'continue] print n ] 'continue ] |
GrahamC 3-Nov-2010 [314] | yes .. but in one word :) |
Ladislav 3-Nov-2010 [315x3] | cc: func [[throw] body [block!]] [catch/name body 'continue] continue: func [[throw]] [throw/name none 'continue] |
for n 1 5 1 [ cc [ if n < 3 [continue] print n ] ] | |
Can be made even more elegant, since FOR is a mezzanine | |
GrahamC 3-Nov-2010 [318] | that would be good |
Anton 3-Nov-2010 [319] | CC being a function, would that mean RETURN or BREAK could not be used? eg. myfunc: func [][ for n 1 5 1 [ cc [ if mycondition [return] ] ] ] (until converted to native?) |
Ladislav 3-Nov-2010 [320x3] | Do you have any problem with it? |
(you should not) | |
Of course, this construct is just for R2, for R3 you have native solution | |
Anton 3-Nov-2010 [323] | No, just wondering. |
Ladislav 3-Nov-2010 [324x4] | A different idea, instantly causing any R2 cycle to "understand continue": cc: func [ {convert a cycle body to "understand" CONTINUE} body [block!] ] [ compose/only [catch/name (body) 'continue] ] continue: func [[throw]] [throw/name none 'continue] ; usage: for n 1 5 1 cc [ if n < 3 [continue] print n ] |
Hope, this is sufficient even for Graham ;-) | |
Any name improvements (the 'cc name looks a bit unnatural) | |
? | |
Anton 3-Nov-2010 [328x2] | Could you put CONTINUE into the CC func context? |
(I mean, wouldn't it be better ?) | |
Ladislav 3-Nov-2010 [330] | yes, that can be done |
Anton 3-Nov-2010 [331] | Ah, but then you need to bind BODY. |
Ladislav 3-Nov-2010 [332] | no problem with that, but it would be incompatible with R3 CONTINUE, then |
Anton 3-Nov-2010 [333x3] | oh I had forgotten it was in R3. |
better outside then. | |
CC -> MAKE-CONTINUABLE ;) | |
Ladislav 3-Nov-2010 [336] | Very understandable, but a little bit too long for my taste |
Anton 3-Nov-2010 [337] | I can't think of a better name. The reason is because it shouldn't be there at all. I think all the rebol loop constructs should be adjusted to use CC by default. |
Ladislav 3-Nov-2010 [338] | All REBOL loop constructs use CONTINUE, but, unfortunately, not in R2 :-( |
Anton 3-Nov-2010 [339] | Well, there's a wish... |
Ladislav 3-Nov-2010 [340] | I don't think you get CONTINUE in R2, if you don't want this "cheap one" |
Anton 3-Nov-2010 [341x2] | Hmmm... hard decision. |
On the balance of things, I think it would make things better; code more readable and more consistent with R3 code, so I'm for it. A better name for CC is definitely needed, though. | |
Ladislav 3-Nov-2010 [343] | What amazes me, (as always in REBOL) is, that the hardest part is to find the best name, not to implement the feature :-) |
Anton 3-Nov-2010 [344] | Well, that just means that the name of a feature is really part of the feature. |
Ladislav 3-Nov-2010 [345] | Regarding the CONTINUE in R2 - I may be wrong, though, maybe Brian would know better? |
older newer | first last |