It would be appreciated if this code was made portable. r2q2 may do this.
;; This program measures how well a file can be compressed ;; #! /usr/local/Gambit-C/bin/gsi (define filename (cadr (command-line))) (define chars (read-all (open-input-file filename) read-char)) (define cnt (length chars)) (define vec (make-vector 256)) (for-each (lambda (c) (let ((i (char->integer c))) (vector-set! vec i (+ (vector-ref vec i) 1)))) chars) (define entropy (- (apply + (map (lambda (x) (if (= x 0) 0 (* (/ x cnt) (/ (log (/ x cnt)) (log 2))))) (vector->list vec))))) (pp entropy)