[plt-scheme] about letrec and continuation : which behavior is correct ? and why ?

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Wed Aug 20 14:33:24 EDT 2008

On Wed, Aug 20, 2008 at 8:57 AM, Sam TH <samth at ccs.neu.edu> wrote:
>
> Note that this rules out the following code:
>
> (define (f x)
>  (define local-var (add1 x))
>  (define (do-stuff . args) ...)
>  (do-stuff x local-var))
>
> which I think would be a big loss.

I don't consider that a big loss.  It's trivial to change this to either

(define (f x)
  (let ((local-var (add1 x)))
    (define (do-stuff . args) ...)  ;; if you refer to local-var freely in here
    (do-stuff x local-var)))

or

(define (f x)
  (define (do-stuff . args) ...)  ;; if local-var is not used in here
  (let ((local-var (add1 x)))
    (do-stuff x local-var)))

> What precisely are we gaining by restricting `letrec'?

The ability to write mutally-recursive programs in a side-effect free
subset of the language.

What precisely are we losing by allowing arbitrary expresions
on the right hand side?

-- 
~jrm


Posted on the users mailing list.