[plt-scheme] a couple of questions

From: John Clements (clements at brinckerhoff.org)
Date: Sat Jan 20 22:10:06 EST 2007

On Jan 20, 2007, at 2:20 PM, Danny Yoo wrote:
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>   (let loop ([input-val (read-prompt)])
>     (with-handlers
>         ((exn:fail:user?
>           (lambda (exn) (printf "Error!~n") (loop (read-prompt)))))
>       (if (not (eof-object? input-val))
>           (begin
>             (printf "~a~n~n" (eval-strict input-val env))
>             (loop (read-prompt)))
>           (printf "~a~n" exit-message))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

A minor point, but perhaps worth mentioning:  I wrote code like this  
piece above about fifty times, and every time it bothered me that I  
had to write 'read-prompt' in three places.  Finally I realized that  
there's no need:

(let loop ()
   (let ([input-val (read-prompt)])
           (lambda (exn) (printf "Error!~n") (loop))))
       (if (not (eof-object? input-val))
             (printf "~a~n~n" (eval-strict input-val env))
           (printf "~a~n" exit-message)))))

I'm glad to see that I'm not the only one who somehow assumed that  
since this binding was changing on every pass through the loop, that  
it would have to be a loop variable.

All the best,

John Clements

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070120/5b1fc720/attachment.p7s>

Posted on the users mailing list.