This is the mail archive of the guile@sourceware.cygnus.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: why undefined return values?


> > and for the scsh code I submitted here, certainly
> > 
> >        (define match #f)
> >        (cond
> >         ((begin (set! match (regexp-search ....)) match) #t)
> >         ...
> >         )
> >        (if match
> >         (display (match:substring match 1))
> >         (display "not found")
> >         )
> > 
> 
> Well, the way I'd write that in normal Scheme style is
> 
> (let ((match (regexp-search)))
>     (cond 
>       (match #t)
>        ....
>     )
>     (if match
>        (display (match:substring match 1))
>        (display "not found")))
> 
> Am I missing a reason why this is bad? It certainly looks more readable to me.

Yes, the expression I wrote is a bit more complicated:

    (let loop ((line (read-line port)))
      (cond
       ((not (string? line)) #f)
       ((begin (set! match (regexp-search re line)) match) #t)
       (else (loop (read-line port)))
      ) )

     (if match ... ...)     

It would make no sense to evaluate match before the first cond test.
Often, there are many more cond tests in front of the one in which the
value I am set!ing comes into play.

My point is that (let (( ...) (.. ..))  ....) is much more of a functional
amalgam than (setq var val).  There is no reason why scoping and binding
should go together.  There is a reason why a handing value and memorising
a variable name for it should go together.

This is why I have become used to, in Emacs Lisp, to never bind values to
variables with let but only implicitely initiate them to nil (Scheme #f).

  (let (var1 var2)
      ... 
      (complicated-relation (setq var1 val1)
           ...
           (setq var2 val2)
           ... )
    )

When a let construction does binding, it offers only a linear (begin ....)
or (progn .... ) relation between the individual bindings.  But usually
complicated-relation is needed. 

> I'm not convinced it's useful enough to put in the Guile core. The way
> most people use Scheme it's not really necessary, and most other implementations
> do not have this behavior.

Extensions should be kept separate from the core.  It could be in some
Guile Extensions module, which later could become part of some further
standardisation process.
 
> Someone already posted setq as a define-syntax macro, which should work in
> all R5RS implementations.

Two were posted.  One worked in Guile, none worked in scsh 0.52

--
phm


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