[plt-scheme] Stylistic (I hope!) question regarding driver loop

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Sat Jan 21 15:42:41 EST 2006

On Jan 21, 2006, at 11:58 AM, Lauri Alanko wrote:

> You can add the definition of evaluate either inside or outside the
> let-expression (depending on whether it depends on main-loop or not).
>
>
> Lauri

Well, I tried taking evaluate out of the letrec, but got an error.  
Leaving it in as a place holder for the real evaluator seems to work

;;Trivial evaluation function - just return the value
(define (trivial-evaluate exp) exp)

;;Main loop - prompt for an S-expression, evaluate it and display
;;the result. To exit, enter (exit).
(letrec
     ((main-loop
       ...stuff
               (main-loop))))))
      (evaluate trivial-evaluate))
   (main-loop))

but only if I define trivial-evaluate first (otherwise, I get an  
error). That's really not a surprise because the loop is entered by  
evaluating the letrec. But I wonder if this is really safe. Can I  
count on a top level define being evaluated before the letrec just  
because it comes first in the source file? I can see that this could  
become a problem because I really don't want to have to tuck a  
complex evaluator inside a letrec. Hmm...maybe that means I need to  
start learning about modules.


===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net

"Good acts are like good poems. One may easily get their drift, but  
they are not rationally understood."
--Albert Einstein





Posted on the users mailing list.