Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Rebol Challenge was: A collection of garbage

From: nitsch-lists:netcologne at: 10-Jul-2003 14:56

Am Donnerstag, 10. Juli 2003 07:59 schrieb A J Martin:
> Carl wrote: > > foo: has [file] [ > > file: read %large-file.txt > > print length? file > > file: none > > ] > > Let's assume that the function was like: > > foo: has [file] [ > file: read %large-file.txt > print length? file > file > ] > > How would one arrange to set the value of 'file to none, while still being > able to return the contents of %large-file.txt ? And do it "nicely"? :) >
most time it is enough to call 'foo again. then the locals of the last call are overwritten. If you must save memory, use one gloval word for all results of all functions. so the next return frees the return-value before. then only the last result is keept from beeing garbage-colected. foo: has [file] [ file: read %large-file.txt print length? file result: file file: none result ] and a funtion calling 'foo returns its result in 'result to, freeing 'foo's result.. also at some point you can say [process foo %file result: none]. but then mazines like append keeo references to 'file too, until theyr next call. as extensioni can imagine [return/clear value] which clears locals, or foo: func[[clear] file].. or such. or auto-clearing and foo: func[[keep]].. but that would break code. and in my experience the "next call clears" - rule works well enough.
> Andrew J Martin > ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/ > -><-
-Volker