This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Challenge


On Wed, Aug 09, 2000 at 02:55:12PM +0900, sen_ml@eccosys.com wrote:
> From: Chris Cramer <crayc@kiwi.pyro.net>
> > hmm... the best way would be to just do something like:
> > 
> > (display output (open-input-file (cadddr command-line)))
> > 
> > or, a less drastic change:
> > 
> > (define output-filename (cadddr command-line))
> > ...
> > (display output (open-input-file output-filename))
> > 
> > Then it'll just get flushed during garbage collection.
> 
> i am confused as to why this should work when not explicitly flushing
> or closing the port originally didn't.  i get the feeling there's
> something going on here that i do not understand.

Ports will get flushed when they closed, and they are closed when they
are garbage collected. However, originally there was:

(define template (dump-port (open-input-file (cadr command-line))))
(define content (dump-port (open-input-file (caddr command-line))))
(define target (open-output-file (cadddr command-line)))

Global defines such as these are never garbage collected, because they
are forever accessible. If you just define the filename, or skip
the define altogether, the port becomes inaccessible after it's used
and is garbage collected.

This is not a problem if you run the script with guile -s, but I wasn't
doing that because I was debugging it. I got very confused when everything
worked but the output file was empty...

> btw, i was going through guile-procedures.txt and i came across
> something named `drain-input'.  would that have worked in place of
> `dump-port'?

IIRC drain-input just tosses the input buffer of a port, so no.

-- 
C. Ray C. aka Christopher Cramer
crayc@pyro.net
http://www.pyro.net/~crayc/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]