[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] with-*-*-port
From: |
Joerg F. Wittenberger |
Subject: |
Re: [Chicken-users] with-*-*-port |
Date: |
28 Feb 2003 17:38:51 +0100 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp) |
true, but there is a problem though
Felix Winkelmann <address@hidden> writes:
> Tony Garnock-Jones wrote:
> >>(define with-input-from-port
> >> (let ((values values))
> >> (lambda (port thunk)
> >> (let ((old ##sys#standard-input))
> >> (##sys#dynamic-wind
> >> (lambda () (set! ##sys#standard-input port))
> >> thunk
> >> (lambda () (set! ##sys#standard-input old))) ) ) ) )
> > Perhaps this would be better capturing standard-input on each
>
> > transition, rather than just the first?
> > (Untested code follows)
>
> > (define with-input-from-port
>
> > (let ((values values))
> > (lambda (inner thunk)
> > (let ((outer '*))
> > (##sys#dynamic-wind
> > (lambda ()
> > (set! outer ##sys#standard-input)
> > (set! ##sys#standard-input inner))
> > thunk
> > (lambda ()
> > (set! inner ##sys#standard-input)
> > (set! ##sys#standard-input outer)))))))
> > Does this make sense, or is it too paranoid?
>
> It *is* paranoid, but it's the safest method.
True, it is paranoid, it is the safest method and it SHOULD be overly
paranoid, i.e., not needed:
1. The ##sys#standard-input is never changed at application level (it
must be hidden from that level), only chicken internal code can
change it.
2. Clean coding would never assign to ##sys#standard-input except by
means of with-input-from-port and friends.
3. As long as this holds true, there will always be a propper nesting
of BEFORE/AFTER hooks from ##sys#dynamic-wind.
Hence this safety should not be needed. The code would have no actual
effect, would it?
If I'm right (skip conclusion otherwise), it would even harm for two
reasons:
a) It wastes some CPU cycles and memory objecst. Not so much of a
problem sometimes.
b) It would encourage to rely on the code and assign to
##sys#standard-* . I.e., it could lead to really bad coding
practice. And *this* would be bad.
Cheers
/Jörg
--
The worst of harm may often result from the best of intentions.