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] |
On Fri, 30 Oct 1998, Maciej Stachowiak wrote: > (define (hash->keys mytab) > (let ((real-tab (cdr mytab)) > (entry->key cadr) > (end (vector-length real-tab))) > (let loop-over-tab ((index 0) > (accum ())) > (if (= index end) > accum > (loop-over-tab (+ index 1) > (let loop-over-bucket ((l (vector-ref real-tab index)) > (accum accum)) > (if (null? l) > accum > (loop-over-bucket (cdr l) > (cons (car l) accum))))))))) hrmm. functional, pretty, and sleek. But I bet this guy is faster: > (define (hash->keys mytab) > (let ((real-tab (cdr mytab)) > (entry->key cadr) > (end (vector-length real-tab))) > (do ((index 0 (+ 1 index)) > (accum () (do ((l (vector-ref real-tab index) (cdr l)) > (accum accum (cons (car l) accum))) > ((null? l)) > accum))) > ((= index end)) > accum))) functional, pretty, sleek, and fast. > ... rewriting working simple-minded code to functional but efficient > code is not hard even by hand, and smart compilers do exist. I guess it takes practice ;) Jay jglascoe@jay.giss.nasa.gov