[racket] Use `set!' or not in this scenario?

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Sat Jul 20 09:35:16 EDT 2013

On Sat, Jul 20, 2013 at 4:16 AM, Norman Gray <norman at astro.gla.ac.uk> wrote:

>
> Can anyone illustrate how that solution would work in Ben's example here?
>

The basic gist of it is that instead of manipulating "the-data", we
manipulate
functions.  So the inner functions f2, f3, ... will change from this:

(define (f2 the-data arg arg …)
      …
      (f3 the-data x y …))

to this:

(define (f2 arg arg …)
  (lambda (the-data)
      …
      ((f3 x y …) the-data)))

We just move the-data to the end of the argument list and curry the
functions.
That makes things more complicated at first, but the inner functions that
don't
actually use the-data can be eta-reduced.  (lambda (x) (f  x)) => f
So f2 eta-reduces to:
(define (f2 arg arg …)
      …
      (f3 x y …))
 and all mentions of the-data disappear in the inner functions (pretty
slick!)
The innermost fx can't be reduced this way, of course, and the callers of f0
have to change to pass the initial value of the-data.

I just did this with an ad-hoc code transformation.  A "monad" formalizes
this.
(and I skipped over a* lot *of detail.)

-- 
~jrm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130720/80d2e0bc/attachment.html>

Posted on the users mailing list.