Rebol Challenge was: A collection of garbage
[1/7] from: Al::Bri::xtra::co::nz at: 10-Jul-2003 17:59
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"? :)
Andrew J Martin
ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/
[2/7] from: carl::cybercraft::co::nz at: 24-Dec-2003 22:22
On 10-Jul-03, A J Martin wrote:
> Carl wrote:
>> foo: has [file] [
<<quoted lines omitted: 11>>
> being able to return the contents of %large-file.txt ? And do it
> "nicely"? :)
foo: does [
print size? %large-file.txt
read %large-file.txt
]
;)
This isn't done nicely, but I think it'd work...
foo: func [/clear /local file][
either clear [
file: none
][
file: read %large-file.txt
print length? file
file
]
]
Usage...
value: foo foo/clear
--
Carl Read
[3/7] from: Al:Bri:xtra at: 10-Jul-2003 21:50
Gabriele wrote:
> foo: has [file] [
> file: read %large-file.txt
> print length? file
> first reduce [file file: none]
> ]
At the moment, Gabiele is in the lead...
Andrew J Martin
ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/
[4/7] from: g:santilli:tiscalinet:it at: 10-Jul-2003 12:06
Hi Andrew,
On Thursday, July 10, 2003, 11:50:43 AM, you wrote:
AJM> At the moment, Gabiele is in the lead...
Other possibilities are:
foo: has [file] [
file: read %large-file.txt
print length? file
get in context [
file': file
set 'file none
] 'file'
]
foo: func [/really /local file] [
either really [
file: read %large-file.txt
print length? file
file
] [
foo/really
]
]
foo: does [
do has [file] [
file: read %large-file.txt
print length? file
file
]
]
foo: does [
use [file] copy [
file: read %large-file.txt
print length? file
file
]
]
etc... What did I win? ;-)
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[5/7] from: carl:cybercraft at: 24-Dec-2003 22:22
On 10-Jul-03, A J Martin wrote:
> Gabriele wrote:
>> foo: has [file] [
<<quoted lines omitted: 3>>
>> ]
> At the moment, Gabiele is in the lead...
By a long shot. :)
Are you suggesting there's still a better way?
--
Carl Read
[6/7] from: fsievert:uos at: 10-Jul-2003 13:29
foo: has [file] [
....
first reduce [file file: none]
]
foo: has [file] [
....
do reduce [first [file:] none file]
]
;)
Frank
[7/7] 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] [
<<quoted lines omitted: 10>>
> 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
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted