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

From: Jos Koot (jos.koot at telefonica.net)
Date: Tue Sep 19 17:11:12 EDT 2006

There is a good chance that the compiler optimizes this for you.
Code in conventional and good style is better optimized than tweaky code, because conventional and good style code is easier 'understood' by the optimizer, I think.
Jos Koot

((((lambda(x)((((((x x)x)x)x)x)x))
   (lambda(x)(lambda(y)(x(x y)))))
  (lambda(x)(write x)x))
 "greetings, Jos") 
  ----- Original Message ----- 
  From: Albert Neumüller 
  To: plt-scheme at list.cs.brown.edu 
  Sent: Tuesday, September 19, 2006 9:37 PM
  Subject: [plt-scheme] Re: Scheme efficiency guidelines (or: the fastest wayto calc a cartesian product)


  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

  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,
    For list-related administrative tasks:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060919/b9813d9b/attachment.html>

Posted on the users mailing list.