This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

coupla small questions



Hello all--

This is probably a more general scheme question, but I'm working with
Guile. . .so I'll try to be brief.

I wrote a small function timer:
  
;;; call example1 (fntimer (#.reduce-init #.+ 0 (1 2 3 4 5)))
;;; call example2 (fntimer (#.reduce-init #.+ 0 #.mydata)
;;;                           mydata is a variable containing numeric list
;;; call example3 (fntimer (#.+ 0 333 444 555)
(define-macro (fntimer fn)
  (let ((start (gettimeofday)))
    (apply (car fn) (cdr fn))
    (let ((end (gettimeofday)))
      (display (string-append "Total runtime: " (number->string (abs
      (- (car start) (car end)))) "s " (number->string (abs (- (cdr start)
      (cdr end)))) "ms\n")))))

This does what I want it to do. . .the only problem is that the
interface basically bites. . .all the #. noise.  What I'd really like
is an interface like:

      (fntimer '(reduce-init + 0 mydata))
      
                   or
		   
      (fntimer '(reduce-init + 0 '(1 2 3 4 5)))

Is this possible?

Secondly, I wrote fntimer to compare the two following implementations of
reduce.  The one is common-list.scm:

   ;;;common-list.scm's reduce is sugar for reduce-init
   (define-public (reduce-init p init l)
     (if (null? l)
        init
        (reduce-init p (p init (car l)) (cdr l))))

against the following version of reduce (inspired in no small part
from Paul Graham's "On Lisp". . .fabulous book BTW):

   (define (reduce fn init lst) (apply fn init lst))

The second version is 2X as fast summing a 100000 elt number list and
15X as fast on string-appending a 3000 elt string list.  My question
is this:  

   is there anything fundamentally wrong (portability, errorhandling, 
   etc.) with the second version?

Thanks and sorry so long.

--Brad (subscribed as knotwell@ix.netcom.com)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]