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

World: r3wp

[Core] Discuss core issues

Maxim
10-Dec-2008
[11452x4]
yep
pretty powerfull too.
I'll put it on rebol.org is that ok?
Graham... FYI, I am working on my args.r module in order to make 
it public... just for you ... adding in-script documentation and 
cleaning up a few details  :-)
[unknown: 5]
12-Dec-2008
[11456x2]
what is the differences between port/size port/state/index and port/tail? 
 Port/tail does seem to point to the last posiition in the file port 
but what about the others.  I know that port/size doesn't really 
tell me the size of the file. I'm wondering thy that is.
I should say that port/tail does point to tail.
eFishAnt
18-Dec-2008
[11458]
I have a situation where I wish inside a while loop I could do a 
continue.  There is break, but I just want to go back to the top 
where my wait sits and wait for the next event coming in.

Has anyone done some solution to this?
Steeve
18-Dec-2008
[11459x4]
i use port/state/index to skip in the opened file.
beware, port/state/index is a zero-based index
to read the first byte of a file, you need to set port/state/inedx: 
0
i think it's a bug but it wroks like that
i should say too, that it works well with the low primitives read-io 
write-io, but i don't remember if it works as well with the standard 
functions like copy
Sunanda
18-Dec-2008
[11463]
EFishAnt -- use  a loop 1 [...] inside the while to simuate a "continue"
n: 1
while [n <> 10][
   loop 1 [
    n: n + 1
    if n = 5 [break]
    print n  
   ]
 ]
sqlab
18-Dec-2008
[11464]
forever [
	catch [
		wait [events]
		do-some-thing 
		if want-no-more [ throw ]
		do-more
	]
]
Steeve
18-Dec-2008
[11465]
generaly, i  like to use a case structure inside my loop.
while [n <> 10][
	n: n + 1
	case [
		n = 5 []		; break
		other-case [...]
		true [print n]   
	]
]
Sunanda
18-Dec-2008
[11466]
With my suggestion, it would look like this (Sqlab's may be more 
elegant)
n: 0
while [n <> 10][
	n: n + 1
   loop 1 [
	case [

		n = 5 [break]		; break
		n = 7 [print "its seven"]  ; example of another case
		true [print n]   
	  ]
	]
]
BrianH
18-Dec-2008
[11467]
R3 has a CONTINUE native. Not much help now I guess...
Pekr
18-Dec-2008
[11468x2]
How does 'continue in R3 work? I can't see it on wiki. Console help 
shows it, so yes, it does exist :-)
It would be good to mentione it eventually in Function notes section 
- there are new usefull R3 funcs .... well, if this one is generally 
usefull :-)
Steeve
18-Dec-2008
[11470]
i have done this too for more clarity:
continue: []
while [n <> 10][
	n: n + 1
	case [
		n = 5 continue		
		other-case [...]
		true [print n]   
	]
]
BrianH
18-Dec-2008
[11471x3]
The R3 continue works the way it does in any structured language 
with a continue operation. It's basically goto the end of the loop, 
while break is goto the point right after the loop.
R3's functions are still in flux. People often expect stuff put into 
the documentation to exist as documented.
Still, CONTINUE is likely to remain as it is.
Sunanda
18-Dec-2008
[11474]
That works. Steeve -- unless there is termination code between the 
end of the CASE and the end of the WHILE. That code does not get 
skipped:

continue: []
n: 0
while [n <> 10][
	n: n + 1
	case [
		n = 5 continue		
		n = 7 [print "it's seven"]
		true [print n]   
  ]
 print ["this gets printed even for n=5...." n]
 ]
BrianH
18-Dec-2008
[11475]
Sorry, my mention of R3 is probably off topic for this group. Nevermind.
Steeve
18-Dec-2008
[11476]
yes Sunanda no code must be inserted between the end of the case 
and the end of the loop.

If you can't refactoring your code to follow this rule, it's useless
BrianH
18-Dec-2008
[11477]
Sqlab's solution will still work though.
eFishAnt
18-Dec-2008
[11478x2]
Thanks, those are clever.  Muchos Appprechioto
I'm sure if I asked for Goto hacks, they must abound as well, or 
perhaps not be bound.
BrianH
18-Dec-2008
[11480]
Outside of rebcode, you can't goto down, but you can goto up with 
CATCH/name and THROW/name. Of course the structured goto replacements 
still work (RETURN, EXIT, BREAK).
Steeve
18-Dec-2008
[11481]
in fact i remember having to simulate a goto command when i tried 
to develop a Z80 emulator.
i had build a simple engine working like that:
code: [
	[ some code....]
	[ some code...]
	[ some code ... GOTO: 1]	; goto the first line of code
]
GOTO: 0
forever [
	GOTO: GOTO + 1
	do pick code goto
]
BrianH
18-Dec-2008
[11482]
That's a pretty standard switch interpreter model.
Steeve
18-Dec-2008
[11483]
yep, even if there is an error in my code, it's very easy to do
eFishAnt
18-Dec-2008
[11484x2]
I was tongue in cheek on that, but then I'm not surprised there is 
an "elegant" goto in REBOL.  Thanks, I am out of the woods with my 
problem, thanks to the best help-desk in the world!
print "Continue hack for a forever loop using Catch and Throw"
n: 0
forever [ ;from sqlab
	n: n + 1
	print join "top of FOREVER LN:" [n]
	catch [
		print "top of CATCH"
		if n > 100 [ break ] 
		if random 10 > 5 [ throw ]
		print "BOTTOM BELOW THROW CONDITIONAL"
	]
	print "BOTTOM BELOW CATCH"
]
print "BREAK forever loop and halt"
halt ;this is what I did to mess with it, sqlab
BrianH
18-Dec-2008
[11486]
continuing: func [code [block!]] [catch/name code 'continue]

continue: func [/return value [any-type!]] [throw/name get/any 'value 
'continue]
Steeve
18-Dec-2008
[11487]
in that case a simple exit or return is enough:
continue: :exit
continuing: func [code][do code]
BrianH
18-Dec-2008
[11488]
No, that would capture real exits and returns.
Steeve
18-Dec-2008
[11489]
like in your case
BrianH
18-Dec-2008
[11490]
Then you add the appropriate function attributes to my case to make 
sure that exits and returns aren't captured ([throw]?).
Steeve
18-Dec-2008
[11491x2]
that should be ok
according to forskip source, perhaps a dual [throw catch] attribute 
is required, i'm not well versed in using such tricks
BrianH
18-Dec-2008
[11493x2]
The [catch] attribute is like a CATCH block for errors in the function, 
in this case used to catch the error! thrown in the source on the 
first and fifth lines. There is no need for the [catch] attribute 
in the CONTINUING function above, or for any function attribute in 
the CONTINUE function above.
By the way, R3 doesn't need anything like the [catch] attribute because 
it does stack traces on errors.
Steeve
18-Dec-2008
[11495]
BrianH, in R3 some functions are not any more natives (ie minimum-of). 
Is that meaning that they will be slower ?
BrianH
18-Dec-2008
[11496]
In some cases, yes. In other cases, changing the functions to mezzanines 
has allowed us to get algorithmic speedups. In more critical cases 
(like loops), functions that used to be mezzanine are now native. 
The overall speed of R3 is greater.
sqlab
18-Dec-2008
[11497]
repeat  n 100 [
	print join "top of loop LN:" [n]
	catch [
		print "top of CATCH"
		if random 10 > 5 [ throw ]
		print "BOTTOM BELOW THROW CONDITIONAL"
	]
	print "BOTTOM BELOW CATCH"
]
Steeve
18-Dec-2008
[11498]
regarding the source of minimum-of and maximum-of, i assume they 
fall in the wrong side
BrianH
18-Dec-2008
[11499x2]
They are infrequently used functions, and as such are a good candidate 
to be mezzanines, for 2 reasons:
- Frees up some native space for more important functions.
- Easier to modify or replace with better functions.
The really interesting thing is the intrinsics - REBOL code called 
internally by natives.
Steeve
18-Dec-2008
[11501]
i see, sort of hooks, but currently there's only 3 intrinsics func, 
is that enough ?