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] |
Maciej Stachowiak <mstachow@mit.edu> writes: > jglascoe@jay.giss.nasa.gov writes: > > 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))) ... Except that I didn't follow the thread, and that the first let probably should be a let*, and that I observe that "entry->key" is defined but never used in both versions .. .. and while you claim > Incidentally, you mentioned order of magnitude improvements of length > of Perl/Python source code vs. C, I think Scheme often gives > improvements on the same scale. isn't that whole bunch not just: (define (hash->keys mytab) (map cadr (apply append (vector->list (cdr mytab))))) Huh? [Example: (define eghash (cons 'eghash (list->vector '(() () ((v1 k1) (v2 k2)) () ((v3 k3)) ())))) > (hash->keys eghash) ==> (k1 k2 k3) ] -Wolfgang.