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

World: r3wp

[Core] Discuss core issues

Chris
30-Mar-2009
[13237]
Returns an unset!, clears the block from given index...
Geomol
30-Mar-2009
[13238x2]
So, beside the unset! returned, PATH is like CLEAR AT ?
Anyone using ALSO?
Steeve
30-Mar-2009
[13240]
everywhere
Geomol
30-Mar-2009
[13241]
Can you give examples?
Anton
30-Mar-2009
[13242]
The primary example use was in functions, to return the contents 
of a variable and also free the variable. eg, this:

	add-one: func [value][1 +  also value value: none]

replaces older code such as this:

	add-one: func [value][1 + first reduce [value value: none]]
Geomol
30-Mar-2009
[13243]
Is that a good example? Why would you set value to none, if it's 
a number? It doesn't matter.
Steeve
30-Mar-2009
[13244x2]
use cases: 
1/ swaping a with b
a: also b a: b
2/ in a function, returning a value after cleaning local vars
func [x /local tmp][
	tmp: a * 2
	also tmp tmp: none
]
error with swaping
a: also b b: a
Geomol
30-Mar-2009
[13246x2]
Hm, a SWAP command could be a good idea, maybe. Or just do:
set [a b] reduce [b a]


About freeing local variables, why would you do that? Don't you call 
your function several times? You give garbage collector more to do 
this way. If it's often the case, that locals should be freed, then 
maybe we need a new function type, that does that?


(I'm asking all this, because I never understood the reason for having 
ALSO.)
When I think about it, much of this is based on assumption how memory 
is handled in REBOL. We don't really know, because it's not documented. 
When is it good to free a local, and when not? There may be something 
wrong, if this should be handled by the programmer (also when it's 
not documented).
Steeve
30-Mar-2009
[13248]
In fact i use ALSO in functions to save the use of temporay variables.

Instead of doing  that:
func  [.. /local result][
	....
	result: ... 	;*** compute result
	... do something before returning the result
	:result    ;** return the result
]

I do:

func  [.. /local result][
	....
	 also (compute the result)
	.(do something before returning the result)
]

It saves the declaration of the result local var
Geomol
30-Mar-2009
[13249]
Ok, your last func should have the /local result, right?
Steeve
30-Mar-2009
[13250]
shouldn't have, right
Geomol
30-Mar-2009
[13251]
Then it kinda makes sense. But then I think about all the internal 
sub-results, REBOL have to handle, and which I guess is freed by 
garbage collection. Is the problem, that REBOL keep locals, also 
when the funciton is finished?
Steeve
30-Mar-2009
[13252]
In R3 it's not only to avoid the use of temporary vars, it's also 
faster (ALSO is native)
Geomol
30-Mar-2009
[13253x4]
If I have a simple local in a language like C, I wouldn't allocate 
and free it every time, I call my function.
A local in C is just a value stored in some memory. I guess, it's 
the same in REBOL? Again we don't really know.
REBOL must have a look-up table for the known words in the context, 
but after that it should just end up at a memory address.
If you free the local every time, REBOL have to allocate that memory 
every time.
Steeve
30-Mar-2009
[13257]
anyway ALSO is faster than using vars
Geomol
30-Mar-2009
[13258]
ok
Steeve
30-Mar-2009
[13259]
in R3
[unknown: 5]
30-Mar-2009
[13260x2]
Hi John, I free locals all the time.
I use also function a lot.
Geomol
30-Mar-2009
[13262]
Have you tested performance when you free locals and if you don't?
[unknown: 5]
30-Mar-2009
[13263]
I also use this clear-locals function which is very similiar to what 
Gabriele made:

    clear-locals: make function! [word][
        word: bind? word 
        set word none
        set in word first first word none
    ]
Steeve
30-Mar-2009
[13264]
in R3 we don't need to free locals
[unknown: 5]
30-Mar-2009
[13265x2]
John, I haven't done a lot of performance checking but I know the 
clear-locals function is working to free memory.
I wish we could supress the garbabe collection and had the tools 
to handle that task ourselves.
Geomol
30-Mar-2009
[13267]
As I see it, it's the garbage collectors job. When I use large series, 
I declare them like this in my functions:
some-series: clear []

Then I reuse the same memory, every time I call my function. I have 
never used ALSO.
[unknown: 5]
30-Mar-2009
[13268]
yes, it is the garbage collectors job but any garbage collector has 
to make assumptions about the data that may not be to optimal to 
your application.
Steeve
30-Mar-2009
[13269]
it's a differrent use case when dealing with series.
even in R3 you need to clear the series
eFishAnt
30-Mar-2009
[13270x2]
Has anyone done anything with REBOL and UNC (looks to me like UNC 
is M$ way of keeping networks and drives from being compatible, just 
like Paul Allen's backslash trick from long ago) http://technet.microsoft.com/en-us/library/cc939978.aspx
where \\servername\sharepoint\subdirectory\filename.


Almost looks like Microsoft took the "Refinement" concept of / and 
unrefined it with \
so, if I am on a M$ network, what is the best way to reach a \\blah\blah\blah\file.blah?
[unknown: 5]
30-Mar-2009
[13272x3]
I think it is:
read %/blah/blah/blah/file.blah
I know you can do it but just forget the syntax.
I don't have access to an open microsoft network currently.
eFishAnt
30-Mar-2009
[13275x2]
wow, thanks Paul.  I think I freaked momenarily.  If I have to do 
it through Windoze I figure I could do a call (as a backup plan)
A link to where Gab answered this, and yes, your example looks correct, 
http://www.rebol.org/ml-display-thread.r?m=rmlJZJQ
Geomol
30-Mar-2009
[13277]
Is this a bug?

>> first [:a/b]
== :a/b
>> type? first [:a/b]
== path!

Shouldn't it be get-path! ?
Henrik
30-Mar-2009
[13278]
R3 responds get-path!, so it might be a bug
Dockimbel
30-Mar-2009
[13279]
There's no get-path! datatype in R2 AFAICT.
Geomol
30-Mar-2009
[13280x2]
I think, you are right! Just a bit confusing, what :a/b mean then. 
It doesn't give an error.
Maybe a combined get-word! and path! ?
[unknown: 5]
30-Mar-2009
[13282x2]
It isn't a path either
This is why I made my as-lit-word function.
Henrik
30-Mar-2009
[13284x2]
I think it's being interpreted as a get-word! with a refinement:

>> type? :a/b
** Script Error: a has no value
** Where: halt-view
** Near: type? :a/b
>> type? :a /b
** Script Error: a has no value
** Where: halt-view
** Near: type? :a /b
>>
and inside the block, it can be interpreted as a path. basically 
get-path! is a good idea. :-)
[unknown: 5]
30-Mar-2009
[13286]
>> as-lit-word? first [:a/b]
== false
>> as-lit-word? first [:a]
== true