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

World: r3wp

[Core] Discuss core issues

[unknown: 5]
18-Dec-2008
[11695]
I have minimized it to a greater extent.
BrianH
18-Dec-2008
[11696]
A read of less than 1 disk page is just as slow as a read of 1 disk 
page.
[unknown: 5]
18-Dec-2008
[11697]
I'm hitting you privately.
BrianH
18-Dec-2008
[11698]
Ouch :)
Steeve
18-Dec-2008
[11699x2]
say Oooooo to relax your sphincter muscles Brian
forget that
Chris
19-Dec-2008
[11701x3]
A 'bind question: how do I construct an object containing blocks 
without changing the blocks' contexts?  This bad:

>> id: #foo
== #foo
>> blk: [id]
== [id]
>> reduce blk
== [#foo]
>> ctx: context append/only [id: #bar bk:] blk
>> reduce ctx/bk
== [#bar]

This good:

>> id: #foo
== #foo
>> blk: [id]
== [id]
>> reduce blk
== [#foo]
>> ctx: magic-context append/only [id: #bar bk:] blk
>> reduce ctx/bk
== [#foo]

How to 'magic-context ?
Ugly answer:

magic-context: func [blk [block!] /local out][
	out: context join extract blk 2 [none]
	set out
 extract/index blk 2 2
]
I was hoping 'construct would do it, but alas not.
Ammon
19-Dec-2008
[11704]
>> ctx: context append/only [id: #bar blk:] reduce blk
>> ctx/blk
== [#foo]
[unknown: 5]
20-Dec-2008
[11705x3]
What is the best way to set all locals in a function to none before 
returning the result of the function if you have an extensive list 
of locals?
Myself I think that should be the default behavior.
I know for recursive operations that may not be desireable but I 
think they could introduce maybe another feature that allows certain 
ones to not be cleared.  For example, add an exclude native to the 
system to exclude the clearing of certain locals.
Geomol
20-Dec-2008
[11708]
Is there a better way than just doing:

var1: var2: var3: ... varN: none
[unknown: 5]
20-Dec-2008
[11709x2]
Well if you got say 15 or more it just looks ugly.
would be nice if you could  just have a command  inside your function 
that says  clear-locals.
Geomol
20-Dec-2008
[11711]
That would require to get access to locals from the outside of a 
function. I'm not away of a way to do that.
[unknown: 5]
20-Dec-2008
[11712]
I don't think so if it could be bound inside the calling function.
Geomol
20-Dec-2008
[11713x2]
*aware* of a way ...
You still need to get easy access to all the locals. Like having 
them in a series.
Sunanda
20-Dec-2008
[11715]
If you know the "name" of the function, then you can get at the variables:
f: func [a b /local c d e] [print mold first :f]
f 1 2
Then you could run a loop for all those after /local
Geomol
20-Dec-2008
[11716]
Ah, that's right! :-)
Gregg
20-Dec-2008
[11717]
1) what is the purpose of clearing the locals?

2) how often do you need to do this, where the list is large? i.e. 
does it indicate a design issue?
[unknown: 5]
20-Dec-2008
[11718x4]
I tried  that after I posted Sunanda but even though I could get 
to them I was still able to out put a value of the local before setting 
them to none that way so what that  meant was that even though I 
attempted to set them to none! that way that it didn't take (and 
didn't give me an error either).
Gregg, to reduce memory overhead and allow the garbage collector 
to give back some memory.
Gregg, I don't think your second question matters to me.  What matters 
is efficiency to me.
Sundanda , here is a test:
Geomol
20-Dec-2008
[11722]
I found a way to set all locals to none, while just specifying one 
of the locals, and it isn't beautiful, I'm afraid:

f: func [/local a b c][
	a: 1 b: 2 c: 3
	print [a b c]

	; This next line set all locals to none:
	set next bind first :f 'a none
	print [a b c]
]

Running the function in the console:
>> f
1 2 3
none none none
>>
[unknown: 5]
20-Dec-2008
[11723x4]
myfunc: func [ /local lcl lcl2][
    lcl: "I still have a value"
    print mold lcl2: next find third get 'myfunc /local
    foreach item lcl2 [print mold item]
    foreach item lcl2 [print mold get :item]
    foreach item lcl2 [set :item none!]
    print lcl
]
Grrr, I see something I did wrong in my test.
myfunc: func [ /local lcl lcl2][
    lcl: "I still have a value"
    print mold lcl2: next find third get 'myfunc /local
    foreach item lcl2 [print mold item]
    foreach item lcl2 [print mold get :item]
    foreach item lcl2 [set :item none]
    print lcl
]
Yeah John, that is the way I think it has to be done by using 'bind.
Geomol
20-Dec-2008
[11727]
My example only works for functions, which doesn't take arguments. 
If a function take argument, you need:

f: func [v /local a b c][
	a: 1 b: 2 c: 3
	print [a b c]

	set next find bind first :f 'a /local none
	print [a b c]
]
[unknown: 5]
20-Dec-2008
[11728]
right
Geomol
20-Dec-2008
[11729]
Hard to read that setting-to-none line, and I haven't found a way 
to do it by a function call (like a clear-locals function).
[unknown: 5]
20-Dec-2008
[11730]
Its a good idea though - isn't it?
Geomol
20-Dec-2008
[11731]
Yes, a native clear-locals seem like a good idea.
[unknown: 5]
20-Dec-2008
[11732]
I agree
BrianH
20-Dec-2008
[11733]
Remember, all of the parameters are locals, not just the ones after 
the /locals refinement.
[unknown: 5]
20-Dec-2008
[11734]
yeah true.  We should be setting the args to none also.
BrianH
20-Dec-2008
[11735]
If you don't want to corrupt things before you return the value from 
the function, use ALSO - that is what it was designed for.
[unknown: 5]
20-Dec-2008
[11736]
Yeah I love Also Brian and glad you implemented that.  But this is 
really related to all the other non returned values.
BrianH
20-Dec-2008
[11737]
R3 doesn't have this problem, so you are not likely to get a native.
Geomol
20-Dec-2008
[11738]
:-) It gets worse, if all parameters should be set to none:

f: func [v /local a b c][
	a: 1 b: 2 c: 3
	print [v a b c]

	set bind head remove find first :f /local 'a none
	print [v a b c]
]

Try:
>> f 42
BrianH
20-Dec-2008
[11739]
Keep in mind that unless you have a known name reference to a function, 
the code inside the function has no idea which function it is inside, 
so a native would need a reference to a function or a word with the 
function assigned to it or it won't work - natives aren't magic.
Geomol
20-Dec-2008
[11740x3]
Hm, I don't need the HEAD, so it can be:
set bind remove find first :f /local 'a none
Brian, do you know, if it's possible from outside a function to specity 
its context? (To be used in the second parameter for BIND.)
*specify*
BrianH
20-Dec-2008
[11743]
You don't need the find either. John, your example with ALSO:

f: func [v /local a b c][
	a: 1 b: 2 c: 3
	print [v a b c]

	also
		print [v a b c]
		set bind remove first :f 'a none
]
Geomol
20-Dec-2008
[11744]
nah, doen't work.