Re: efficiency of let used in a binding

From: Lars Thomas Hansen <lth_at_ccs.neu.edu>
Date: Tue, 21 Oct 1997 10:39:00 -0400

Brian Denheyer <briand_at_soggy.aqua.com> writes:

>Lars Thomas Hansen writes:
>
> > short-lived objects cheap. Writing a generational collector for STk is
> > left as an exercise for the reader.
>
>ROTFL

Eh?

> > In the given situation, rewriting the program as
> >
> > (define (mouse-motion x y)
> > (set! new-x (transform x))
> > (set! new-y (transform y))
> > ...)
> >
>
>Dumb question, but, I assume I want new-x and new-y to be globals ?

Sorry, my fault, I meant

  (define (mouse-motion x y)
    (set! x (transform x))
    (set! y (transform y))
     ...)

which works since x is not used in the calculation of y, and new-x and
new-y were local (in the original) anyway. Of course, this presupposes
that x and y are not used in '...'. If that's the case, this should
reduce consing (in STk).

David Fox's solution

>(define mouse-motion
> (let ((new-x #f) (new-y #f))
> (lambda (x y)
> (set! new-x (transform x))
> (set! new-y (transform y))
> ...)))

also works, of course, but may get you into trouble if you have threads.

--lars
Received on Tue Oct 21 1997 - 15:38:59 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST