[plt-scheme] Re: Scheme efficiency guidelines (or: the fastest way to calc a cartesian product)

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Sep 19 15:40:58 EDT 2006

I think that in this particular case the difference is likely to be
negligible. Perhaps more importantly, this seems unlikely to be the
source of any significant inefficiency in your program. I suggest you
start with a profiler and think about data structures, not local
tweaks like that.


At Tue, 19 Sep 2006 21:37:43 +0200, "Albert Neumüller" wrote:
> Hi!
> Consider the following code (that I've just seen):
> (define (length=2? any)
>  (and (cons? any)
>       (cons? (rest any))
>       (empty? (rest (rest any)))))
> I would have written (or rearranged the code of) length=2? like this:
> (define (lenght=2? any)
>  (and (cons? any)
>       (local ((define the-rest (rest any)))
>         (and (cons? the-rest)
>              (empty? (rest the-rest))))))
> This avoids evaluating (rest any) twice.
> But who knows - maby setting up a "local define" thus putting the
> pointer (or however it is done) into memory (and later garbage
> collecting it) is actually less
> efficient than just doing the evaluation twice!?
> This is the sort of thing I am interested in. Of course it depends on
> the scheme interpreter that's used and other factors.
> But I suppose on average, there could be some coding guidelines or
> conventions - for speed-efficiency, for readability, for
> memory-efficiency.
> On the otherhand, Scheme probably shines more for its elegance, than
> for its speed, so maby most people using Scheme, favour elegent code,
> rather than speed -
> and I'd rather code the way people in the
> Scheme-community code (and know what style is favoured), than try and push
> speed-efficiency in a language whose main purpose is not speed-efficieny in the
> first place.
> Which lenght=2? would you use? How would you write cartesian product?
> Any kind comments welcome!
> Kind regards,
> Albert
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.