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

World: r3wp

[Core] Discuss core issues

[unknown: 5]
31-Mar-2009
[13345x2]
The also function should be used as the last line of your function.
I gotta run for a bit but will be back in about an hour or sooner.
Geomol
31-Mar-2009
[13347x3]
Yes, I understand that. What I don't understand, is how you call 
these functions, and what does on with the data, you get returned 
from your function. Do you have code examples online, I can look 
at?
what *goes* on ...
Using ALSO returns some data. If your code look like this:

mp3-data: load-mp3-function


and that load-mp3-function ends with an ALSO, setting the local var 
to none, you still have a full copy in mp3-data. Actually you end 
up having 2 copies for some time, until the garbage collector frees 
the local version. Later in your code, you need to set mp3-data to 
none to free to memory (which the garbage collector does). Now, is 
this how you use ALSO and why you need it?
Izkata
31-Mar-2009
[13350x5]
Most of mine are for conciseness - for example, when no data needs 
to be returned:

Client: first wait Listen
Data: also (copy Client) (close Client)
but, like before, say that happened in a function
Process: func [Client][
   ..do stuff..
   return also (copy Client) (close Client)
]

Client: first wait Listen
Logfile/add Process Client
I'll look for some actual code I'm using soon
Pread: func [URL /local Port][
   Port: open/binary URL
   Port/timeout: 3 * 60
   return also (copy Port) (close Port)
]
Geomol
31-Mar-2009
[13355x2]
What happens, if the connection fails?
Does my version work the same as yours beside the timeout?

newPread: func [URL] [read/binary URL]

And can the timeout be set somewhere in the system object?
[unknown: 5]
31-Mar-2009
[13357]
f: has [file][file: read %somefile also copy/part file 30 file: none]
Geomol
31-Mar-2009
[13358x2]
My guess is, that your version using ALSO use the double memory, 
that mine does (because of the copy).
Paul:

f: does [copy/part read %somefile 30]
[unknown: 5]
31-Mar-2009
[13360]
John, yes true but what if you want to do several things with the 
local in the function?  Are you going to copy it every time?
Geomol
31-Mar-2009
[13361]
Then do:


f: has [file] [file: copy/part read %somefile 30 comment "do something 
with the file" return file]
[unknown: 5]
31-Mar-2009
[13362x2]
Yeah my example used copy so that might defeat it.
f: has [q][q: [] append q read %blah remove/part q 20 also q q: none]
Geomol
31-Mar-2009
[13364x3]
That doesn't work. your local q holds data after returning from F. 
(maybe an error)
>> f: has [q] [q: [] append q "kdfjkd" also q q: none]
>> a: f
== ["kdfjkd"]
>> a
== ["kdfjkd"]
>> source f

f: func [/local q][q: ["kdfjkd"] append q "kdfjkd" also q q: none]
It seems, q has data in the end.
[unknown: 5]
31-Mar-2009
[13367]
I didn't try it :-)
Geomol
31-Mar-2009
[13368]
My opinion right now is, that ALSO sucks big time! :-)
Maybe someone can convince me otherwise.
[unknown: 5]
31-Mar-2009
[13369]
I couldn't but I see the difference using it.
Geomol
31-Mar-2009
[13370x2]
It seems hard to use, it often result in using twice the memory, 
that people expect. And it might even lead to pad program structure.
pad -> bad
Izkata
31-Mar-2009
[13372]
newPread: func [URL] [read/binary URL]  ;  I only want the large 
timeout in this function, not in other 'read calls


f: has [file] [file: copy/part read %somefile 30 comment "do something 
with the file" return file] ; I'm also going for readability, otherwise 
I would have done something like this with the original code
[unknown: 5]
31-Mar-2009
[13373x2]
John, actually the piece I think I was showing you the first time 
is what I meant.  The series in the second one is actually desired 
behavior.
f: func [/local q][q: "blahblahblahblahblah" also q q: none]
Geomol
31-Mar-2009
[13375x2]
Is this expected behaviour?

>> f: func [/local q][q: "blahblahblahblahblah" also q q: none]
>> a: f
== "blahblahblahblahblah"
>> source f
f: func [/local q][q: "blahblahblahblahblah" also q q: none]
>> insert a "hmm"
== "blahblahblahblahblah"
>> source f
f: func [/local q][q: "hmmblahblahblahblahblah" also q q: none]
>> a: none
== none
>> source f
f: func [/local q][q: "hmmblahblahblahblahblah" also q q: none]
Izkata, you got a point with your Pread. But it's not a secure function, 
because it may crash. Let me see, how I would make such a function...
[unknown: 5]
31-Mar-2009
[13377x2]
Works for me John
>> a: f: has [q][q: "blahblahblahblahblah" also q q: none]
>> a
== "blahblahblahblahblah"
Geomol
31-Mar-2009
[13379]
Now do:
source f
[unknown: 5]
31-Mar-2009
[13380x2]
>> f
== "blahblahblahblahblah"
>> a: f
== "blahblahblahblahblah"
>> source f
f: func [/local q][q: "blahblahblahblahblah" also q q: none]
what is wrong with it?
Geomol
31-Mar-2009
[13382]
So what does your q: none at the end do? It doesn't release any memory.
[unknown: 5]
31-Mar-2009
[13383]
I believe it does.  I believe that q will be freed.
Geomol
31-Mar-2009
[13384]
You can see, it doesn't this way:

>> f: func [/local q][q: "blahblahblahblahblah" also q q: none]
>> a: f
== "blahblahblahblahblah"
>> insert a "more blahblahblahblah"
== "blahblahblahblahblah"
>> source f

f: func [/local q][q: "more blahblahblahblahblahblahblahblahblah" 
also q q: none]

Look at the source of f. Notice the "more blahblah...."
[unknown: 5]
31-Mar-2009
[13385x5]
Oh, I see.
then what about this:
a: f: has [q][q: copy "blahblahblahblahblah" also q q: none]
That last one I forgot is no different then the one I showed you 
earlier.
So I don't know in this case.  Is q actually set to none or would 
it be anyway on the return from the function since it used copy? 
 Dunno.
TomBon
31-Mar-2009
[13390]
unfortunatly the same story...
does anybody knows why a replace on the second and third also
changes the first letter?  ^JKSE = %5E/KSE and  ^IKSE = %5E-KSE
but ^MERV = %5EMERV and therefore okay.

	probe load replace/all  mold "^MERV" #^ "%5E"
	probe load replace/all  mold "^JKSE" #^ "%5E"
	probe load replace/all  mold "^IKSE" #^ "%5E"

any advise is highly appreciated...
tom
Geomol
31-Mar-2009
[13391]
Paul, in your last example with copy, the q memory is released, and 
the string after copy remains. So this actually is a version with 
something gained. Now I have to think, if I would do it this way.
Izkata
31-Mar-2009
[13392x3]
Tom: it's not the replace that's doing it...
>> "^IKSE"
== "^-KSE"
>> "^MERV"
== "^MERV"
>> "^JKSE"
== "^/KSE"
>> "^IKSE"
== "^-KSE"
but I have no actual answer
Well, ^I is a control-i.. and in vim, that inserts a tab.  ^- is 
the tab character in Rebol