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
[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
[13392x4]
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
I must go to class now
TomBon
31-Mar-2009
[13396]
thx for the info izkata.
Geomol
31-Mar-2009
[13397x2]
Paul, I would probably do:

o: context [q: "blahblah" f: does [insert q "more blah" q]]


And my that have full control over q. It depends on the application, 
I guess.
my -> by
[unknown: 5]
31-Mar-2009
[13399]
I'll stick with ALSO.  ;-)
Geomol
31-Mar-2009
[13400x5]
Izkata, about the timeout. It seems here, that when the open/binary 
returns, the data is immediately available, so the timeout has no 
effect. I'm on OS X, maybe it's different under windows?
Anyway, I can now see, how you use ALSO with ports. By using a function 
approach, you choose to copy the data out to some further external 
computation. And it's up to the user of the function to free the 
data, when finished. I would take an object approach and store the 
data in the object. Then external computation can work on the data 
in the object. I feel, it's confusing using ALSO, but maybe it's 
just me.
An object approach could look like this:

Ports: context [
	Port: none
	Data: none

	Pread: func [URL] [
		either error? try [Port: open/binary URL] [
			print ["Can't open:" URL]
			false
		][
			Data: copy Port
			close Port
			true
		]
	]
]
Using it would then be:

if Ports/Pread http://www.rebol.com[
	... do something with Ports/Data ...
]
Where I see a potential problem with ALSO, is if you in a function 
load a local var with a huge amount of data, say 1GB. And then to 
release that data ends your function with:
also copy local-data local-data: none


At that moment between the two arguments to ALSO, you have 2 GB of 
data allocated. The first 1 GB is freed, when the garbage collector 
comes to it.
[unknown: 5]
31-Mar-2009
[13405]
So is this your assurance to us that we will never see ALSO in your 
code?
Geomol
31-Mar-2009
[13406]
No no, I never say never. ehh ;-)
Izkata
31-Mar-2009
[13407]
Geomol: [Izkata, about the timeout. It seems here, that when the 
open/binary returns, the data is immediately available, so the timeout 
has no effect. I'm on OS X, maybe it's different under windows?]

I'm on Ubuntu  ;)  but yeah, now that I think about it, that's true. 
 Originally it was written differently, and the error appeared to 
be on the copy.  I added it when mininova was timing out on certain 
requests due to high load - it seemed to make a difference then, 
but I don't know if it was coincidence or not.
Graham
31-Mar-2009
[13408]
mininova ? torrenting?
Izkata
31-Mar-2009
[13409x2]
Yeah, the internal function that RSS plugins on Azureus use broke 
at some point, so I'm doing it this way now.  Much nicer, as I can 
collect more information, etc
If you're thinking I'm making a torrrent client in Rebol, not yet 
 ;)
Graham
31-Mar-2009
[13411]
I suspect R2 is not up to it ...
Izkata
31-Mar-2009
[13412x2]
Probably not, but it would be interesting to try
Then again, R2 has surprised me with my current project
Graham
31-Mar-2009
[13414]
networking is not a strong point
Anton
31-Mar-2009
[13415x2]
Geomol, your last "potential problem with ALSO" is not exclusive 
to ALSO. It's a potential problem anywhere COPY is abused by a programmer 
not knowing what's going on.

The way to return the large amount of data and to release the local 
from it is of course like this:

	also local-data local-data: none
load-mp3-data: func [file /local contents][
	contents: read/binary file
	; <- modify contents here
	also contents contents: none
]

data: load-mp3-data %song.mp3
Graham
31-Mar-2009
[13417]
so this frees contents??
Steeve
31-Mar-2009
[13418]
just to say there is no need  anymore to unset the local vars in 
R3
Anton
31-Mar-2009
[13419x4]
In the load-mp3-data function above, a large binary series is loaded 
and contents set to refer to it. The ALSO line returns the binary 
series and unsets CONTENTS so that it no longer refers to the binary 
series. The usage code below the function definition takes the return 
value (the binary series) and sets DATA to it.

So effectively the variable referencing the binary series has been 
switched with another one.
(Steeve, yep.)
Graham, no, it just "unhooks" the local word CONTENTS from the binary 
series data.
Which is a good thing to do, because now the function does not maintain 
a reference to the large binary series after it has been called.