[CM] iterating over a hash table

Michael Winter mwinter at unboundedpress.org
Tue Dec 15 18:12:43 PST 2009


Dear All,

In the s-7 documentation, it says that a hash-table is a vector of alists
and can be iterated over by vector-ref.

In the following code (vector-ref table 1) throws a wrong-type-arg and I
cannot figure out how to iterate over the table:

---------------------------

(define (entropy list)
   (let ((table (make-hash-table)))
    (loop for e in list
          do (if (table e)
               (set! (table e) (+ (table e) 1))
               (begin (set! (table e) 1))))
     (vector-ref table 1)
    ))

(entropy '(0 1 0 0 1 0))

--------------------

Any help will be much appreciated.

Best,

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/cmdist/attachments/20091215/ad25da09/attachment.html 


More information about the Cmdist mailing list