chicken-users
[Top][All Lists]
Advanced

[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: 01 Mar 2003 12:01:32 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)

Felix Winkelmann <address@hidden> writes:

> Joerg F. Wittenberger wrote:
> > 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.
> >
> 
> 
> What about
> 
> (current-input-port <PORT>)
> 
> ?
> 
> It may be questionable (from a language lawyerly point of view), but
> it's pretty handy...

Really bad practice.  (Said with bitter sound from 20 year of
experience. ;-)

> > 2. Clean coding would never assign to ##sys#standard-input except by
> >    means of with-input-from-port and friends.
> 
> Right, but the form of current-input-port above is just
> a thin wrapper around the assignment.
> 
> > a) It wastes some CPU cycles and memory objecst.  Not so much of a
> >    problem sometimes.
> 
> I guess we have no choice to it play safe, here.

Sorry, this was actually not the main argument.  I argue against
error _correction_ code.  People have a tendency to rely on it.  They
would assign to global variables...  Hell would break loose.

Still, I might be wrong altogether, but if I'm right, then we should
at most have error _detection_ code like this:

(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 ()
           (unless (eq? inner ##sys#standard-input)
                   (error "bad code broke the program"))
           (set! ##sys#standard-input outer)))))))

This way it would catch the errors instead of hiding them.

Hm.  Now that I see the code, I start to like it.

Cheers

/Jörg

-- 
The worst of harm may often result from the best of intentions.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]