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

World: r3wp

[Rebol School] Rebol School

BrianH
15-Mar-2010
[3012x3]
Sunanda, I actually use 'local in some functions as a extra temporary 
variable. It has a good name for that use.
Ladislav, good catch on the op keywords in R2 :)
Btw, if RETURN and EXIT go definitional in R3, 'return and 'exit 
will effectively become keywords in functions.
Ladislav
15-Mar-2010
[3015x2]
Certainly not in all functions, if I understood Carl well, he seems 
to plan to have two types of functions:
- functions with dynamic Return
- functions with definitionally scoped Return
(and the word return: in the spec seems to be the discerning indicator)
Andreas
15-Mar-2010
[3017x2]
And even if all functions get definitionally scoped RETURN/EXIT, 
they wouldn't become keywords at all.
A simple `return*: :return` should do the trick ...
PeterWood
15-Mar-2010
[3019x2]
It seems that I was quite wrong about local being a reserved word 
- it's all in how your write the function specification:


>> func-with-local-called-local: func [/local] [print local: "my 
local word"]

 >> func-with-local-called-local                                  
             
my local word

>> local

** Script Error: local has no value

** Near: local
... which also explains the "apparent" inconsistency in Sunanda's 
list of function creation mezzanines ... both funct and has always 
specify the local refinement in the funciton specification.
BrianH
16-Mar-2010
[3021x5]
Ladislav, you keeep suggesting that there will be the option of dynamically 
scoped RETURN and EXIT if we switch to definitionally scoped. There 
is no indication that this is the case, and the increased complexity 
that would add to function calls is a serious indication otherwise. 
It's probably going to be only definitional or only dynamic, not 
an option of either/or. And either way we will need a workaround 
attribute: something like [throw] for dynamic, something else for 
definitional.
The word return: in the spec is compkletely unrelated to dynamically 
vs. definitionally scoped return, it is just to specify the typespec 
of the return value.
compkletely -> completely
Andreas, MAKE function! doesn't execute the code in the code block, 
it just makes the function. Your workaround applies to the code when 
it is executing. When the function is being made, the words 'return 
and 'exit will be treated specially in the function code block (if 
we go definitional for those functions), but when the code is run 
later the words are nothing special. It's similar to the situation 
with 'self and BIND or MAKE object!.
All in R3 of course.
Ladislav
16-Mar-2010
[3026x2]
you keeep suggesting that there will be the option of dynamically 
scoped RETURN and EXIT if we switch to definitionally scoped. There 
is no indication that this is the case

 - citation: "Allows return as a dynamic function to still work (when 
 return not in function spec.)" see http://www.rebol.com/r3/notes/errors.html
for me, it is an indication
BrianH
16-Mar-2010
[3028]
That is why I said that the section in question needs to be rewritten 
and split up. As it is it makes no sense and mixes unrelated stuff.
Ladislav
16-Mar-2010
[3029]
It makes the above sense to me, so, I do not propose a modification.
BrianH
16-Mar-2010
[3030x3]
And it wouldn't work with EXIT, since the dynamically scoped version 
of the function wouldn't be able to call the definitionally scoped 
RETURN. The whole section gives the impression of not being thought 
through. And we're in the wrong group for this discussion.
Easy to bind, the word is in the spec block.
, "Extra value on function frame." It doesn't mention two values.
It doesn't matter though - I'm sure whatever we all decide on will 
be fine.
Ladislav
16-Mar-2010
[3033x2]
Just a note, which may as well be put here, I guess: since R2, Rebol 
"mixes" definitionally scoped and dynamic constucts, and it looks, 
that this mix will stay with us even in R3
(but, of course, the proportions may change)
Gabriele
16-Mar-2010
[3035]
I understood Carl's proposal in the same way as Ladislav...
Andreas
16-Mar-2010
[3036]
So did I ...
BrianH
16-Mar-2010
[3037]
Continuing in the right group...
Janko
20-Mar-2010
[3038]
is there any word that would let me join two objects together?
Henrik
20-Mar-2010
[3039]
make obj1 obj2
Janko
20-Mar-2010
[3040x3]
aha.. I can just use multiple make
or what you said.. even better in my case
cool things :)
Henrik
20-Mar-2010
[3043]
it creates a new object, though. in R3, you can use the extend function 
to extend an existing object with one new value.
Steeve
20-Mar-2010
[3044]
extend does not do that (though it could, just a mezz).
but this do it:
>> append obj1 body-of obj2
Henrik
20-Mar-2010
[3045]
extend extends with a single value, where append can extend with 
any values.
Davide
21-Mar-2010
[3046]
Just for fun (it's a slow sunday today) I've wrote a rebol version 
of the code used as benchmark in this page http://tinyurl.com/5nezt9

here's the code:

REBOL []

person: make object! [
	_count: none
	_prev: none
	_next: none
	
	_construct: func [n] [_count: n]
	get-prev: does [_prev]
	set-prev: func [pr] [_prev: pr]
	get-next: does [_next]
	set-next: func [nxt] [_next: nxt]
	shout: func [shout nth /local aux] [
		if shout < nth [
			return shout + 1
		]
		aux: get-prev aux/set-next get-next
		aux: get-next aux/set-prev get-prev
		1		
	]
]

chain: make object! [
	
	_first: none
	_last: none
	
	_construct: func [size /local current] [
		repeat i size [
			current: make person []
			current/_construct i
			if none? _first [_first: current]
			if not none? _last [
				_last/set-next current
				current/set-prev _last 
			]
			_last: current
		]
		_first/set-prev _last
		_last/set-next _first
	]
	
	kill: func [nth /local current shout] [
		current: _first
		shout: 1
		while [not equal? current current/get-next] [
			shout: current/shout shout nth
			current: current/get-next
		]
		_first: current		
	]	
]

start: now/precise
iter: 100000
loop iter [
	current-chain: make chain []
	current-chain/_construct 40
	current-chain/kill 3
]

print ["Time per iteration =" (difference now/precise start) / iter 
]
halt

which give me:
Time per iteration = 0:00:00.00080234

802 microsecond that is the slower time of the benchmark, 

but not SO slow, php is near with 593 microsecond, jython 632 ... 
.(the test system is pretty like mine so i can compare the result)

There's a way to improve the performance?
Henrik
21-Mar-2010
[3047]
if not = unless

also perhaps:

if none? _first [_first: current] = any [_first _first: current]

not equal? = not-equal?

Didn't check if there are some mezzanines in there, though.
Davide
21-Mar-2010
[3048]
a bit better:
Time per iteration = 0:00:00.00077844
Henrik
21-Mar-2010
[3049x2]
any instance of IF can possibly be replaced by ANY or ALL.
get-prev: does [_prev]
set-prev: func [pr] [_prev: pr]
get-next: does [_next]
set-next: func [nxt] [_next: nxt]


These will also slow things down. I'm not sure if you can get rid 
of them.
Pekr
21-Mar-2010
[3051]
jython? So python version emulated in JAVA is faster than native 
REBOL? :-)
Henrik
21-Mar-2010
[3052]
Davide, try an R3 version too.
Davide
21-Mar-2010
[3053x3]
java is in the class of c++ in performance AFAIK

I remember the in 1998 there was a mame - java applet that could 
run phoenix at 100% of the velocity with no skipframe (I had a pentium 
100 Mhz at that time)
using _prev and _next instead of function the result is:
Time per iteration = 0:00:00.00056687
with R3:
Time per iteration = 0:00:00.00034359
Geomol
21-Mar-2010
[3056]
I don't think, Java is as C++ in performace. C++ can be compared 
to C in performace, and Java is at least 8 times slower. See e.g.:
http://www.timestretch.com/FractalBenchmark.html
Henrik
21-Mar-2010
[3057]
R3 performance: Interesting. :-)
Davide
21-Mar-2010
[3058]
Yes, I meant in the same class if compared to ruby, python or similar.

java is slower than c++ (but I think that 8x slower is not realistic 
in common usage)
Paul
21-Mar-2010
[3059]
David you can dump those mezzanines and just use make function! instead 
of 'does and 'func.  Maybe use the operators such as <> instead of 
not equal? and use chain assignment here and there were applicable.
Davide
21-Mar-2010
[3060]
a bit OT: yesterday I've discovered that compiled VB6 run as fast 
as tcc in number crunching :-)
Steeve
21-Mar-2010
[3061]
http://tinyurl.com/5nezt9,already dead ?