[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

letrec suggestion



The section on letrec in R4RS says that:

+ \proto{letrec}{ \hyper{bindings} \hyper{body}}{essential \exprtype}}
+ 
+ \syntax
+ \hyper{Bindings} should have the form
+ \begin{scheme}
+ ((\hyperi{variable} \hyperi{init}) \dotsfoo)\rm,%
+ \end{scheme}
+ and \hyper{body} should be a sequence of
+ one or more expressions. It is an error for a \hyper{variable} to appear more
+ than once in the list of variables being bound.
+ 
+ \semantics
+ The \hyper{variable}s are bound to fresh locations holding undefined
+ values, the \hyper{init}s are evaluated in the resulting environment (in
+ some unspecified order), each \hyper{variable} is assigned to the result
+ of the corresponding \hyper{init}, the \hyper{body} is evaluated in the
+ resulting environment, and the value of the last expression in
+ \hyper{body} is returned.

In particular, the last bit says that all of the inits have to be
evaluated before the respective variables are assigned their values.
I think that this is an unnecessary restriction on implementations -
implementations should be free to bind the variables to the proper
values whenever they want to.  (In fact, many implementations don't
obey the above restriction.)  Was the above section really meant to be
so restrictive, and, if so, why?

david carlton
carlton@husc.harvard.edu

       It's OBVIOUS..  The FURS never reached ISTANBUL..  You were an
       EXTRA in the REMAKE of ``TOPKAPI''..  Go home to your WIFE..
       She's making FRENCH TOAST!

Here's a test program that often shows up implementations which don't
obey the above restriction:

(letrec  ((n 0)
          (k (call/cc (lambda (x) x))))
  (set! n (+ n 1))
  (k (lambda (x) n)))