Re: efficiency of let used in a binding

From: Erick Gallesio <>
Date: Sun, 26 Oct 1997 13:13:30 +0100

Brian Denheyer writes:
> I just caught myself doing the following :
> (define (mouse-motion x y)
> (let ((new-x (transform x))
> (new-y (transform y)))
> ...))
> (bind drawing "<Motion>" mouse-motion)
> I don't understand how scheme allocates "local" variables. Is it a
> c-like thing where it's pushed on the stack and then popped or is the
> variable allocated and then when the routine returns the space must be
> gc'ed.
> Obviously if the space is being allocated then a procedure bound to
> mouse motion could generate a _lot_ of allocation which would be very
> inefficient.

Yes this is the case with the current implementation. The real question here
is: "Is it annoying?". Until now, I have already written pieces of code which
use this scheme and performances were not too bad (even if I agree that they
could be better). If you suffer from performance penalty, of course, you'll
have to try to avoid consing, and several responses to your message have been
given in this list for that.

> Common sense says that local variables are implemented on the stack so
> I'm OK and can continue to use let's in procedures which are being
> used in event bindings.

It is a little bit hard for an interpreter and easier for a compiler.
And for now you probably have to do ugly set! as you said. However, in some
extent, it is more important to have clean code than efficient code,
        a) machines are more and more powerful,
        b) your Scheme code could be compiled

OK, the a) reason is probably not a good one, but the b) one is probably not
too far. I take the occasion of this mail to announce that Manuel Serrano, the
author of the Bigloo compiler has now a TA position at the University of Nice
and that we will work together to provide compilation for STk (and by the way,
more compatibility between both "implementations"). Since Manuel has
just arrived we have not really started the work, but it should be done soon
and we hope to provide something in a reasonable timing.
For people who don't know what is Bigloo, here is an extract of the Scheme

   BIGLOO is a Scheme interpreter and compiler. It conforms to the
   IEEE-Scheme standard (IEEE P1178) with some extensions, such as
   regular expression parsing (RGC), a lexical analyzer generator, a full
   foreign function interface, and a pattern matching compiler. Bigloo
   can also compile modules written in Caml (an ML dialect), letting you
   mix Scheme, ML, and C. Object-oriented programming is provided by
   Meroon v3. The main goal of Bigloo is to deliver small and fast stand
   alone applications. Bigloo produces ANSI C and hence should be easy
   to port. It runs on Sparc (1, 2, 10), SONY-NEWS (MIPS R3000), IRIS
   Indigo (MIPS R3000), Sun 3/60, DecStation 3100, PC-486 (linux), and
   HP-PA (730). It is available by anonymous ftp from []

                -- Erick
Received on Sun Oct 26 1997 - 12:23:49 CET

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