[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 11:13:22 EDT 2006

Hi,
Are you aware of the fact that most scheme compilers do some optimization for you? Straightforward code is easier optimized than complicated code. Hand made optimization may even impede the optimizer of the compiler. Because you have no more than 2.5 month of experience, I suggest that you focus on good style first and follow the guidelines of HTDP. 
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 4:50 PM
  Subject: [plt-scheme] Re: Scheme efficiency guidelines (or: the fastest wayto calc a cartesian product)


  Hello again!

  (cartesian-product1c can be further optimized (or not?) as is shown in
  cartesian-product1d below)

  Concerning cartesian-product1c: Instead of passing x-single as a
  parameter the whole time, we create a local expression:

  ;;===================================================
  ;;cartesian-product1d : (listof SV) -> (listof onepair)
  (define (cartesian-product1d alist)
    (local ((define (do-cartesian1d x-single x-rest)
              (local ((define (cartesian-with-fixed-x1d y)
                        (cond
                          [(empty? y) (cond
                                        [(empty? x-rest) empty]
                                        [else (do-cartesian1d (first
  x-rest) (rest x-rest))])]
                          [else (cons (make-onepair x-single (first y))
                                      (cartesian-with-fixed-x1d (rest y)))])))
                (cartesian-with-fixed-x1d alist))))
      (cond
        [(empty? alist) empty]
        [else (do-cartesian1d (first alist) (rest alist))])))
  ;;===================================================

  Kind regards,
  Albert Neumüller
  _________________________________________________
    For list-related administrative tasks:
    http://list.cs.brown.edu/mailman/listinfo/plt-scheme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060919/0e45fb6f/attachment.html>

Posted on the users mailing list.