Anonymous user
Letter frequency: Difference between revisions
completely RNRS Scheme with the exception of format, uses native Scheme character representations, more canonical indentation, and an association list instead of a vector
(→{{header|jq}}: tidy) |
(completely RNRS Scheme with the exception of format, uses native Scheme character representations, more canonical indentation, and an association list instead of a vector) |
||
Line 2,277:
=={{header|Scheme}}==
Using guile scheme 2.0.11, but the functions that don't use format should work in any implementation.
Note that this prints the scheme representations of characters in no particular order.
<lang scheme>(use-modules (ice-9 format))
(if
(eof-object? (peek-char port))
table
(char-freq port (add-char (read-char port) table))))
(cond
((null? table) (list (list char 1)))
((eq? (caar table) char) (cons (list char (+ (cadar table) 1)) (cdr table)))
(#t (cons (car table) (add-char char (cdr table))))))
(define
(if
(not (null? table))
(begin
(format #t "~10s~10d~%" (caar table) (cadar table))
(format-table (cdr table)))))
(define (
(format-table (char-freq (
(print-freq "letter-frequency.scm")</lang>
▲(define (count-char-freqs)
Output when reading own source:
#\s
#\e
#\d 19
#\l
#\space 97
#\i
#\c
#\9 1
#\f 21
▲(define (show-char-freq let-num)
#\a
#\t
#\) 48
#\newline 25
#\n 18
#\h 13
▲ r 13436
▲ u 6489
▲ v 1902
▲ w 1968
▲ x 617
▲ y 3633
=={{header|Seed7}}==
|