Letter frequency: Difference between revisions

defined format-table in terms of for-each
(completely RNRS Scheme with the exception of format, uses native Scheme character representations, more canonical indentation, and an association list instead of a vector)
(defined format-table in terms of for-each)
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.
Line 2,296:
 
(define (format-table table)
(for-each (lambda (t) (format #t "~10s~10d~%" (caarcar tablet) (cadarcadr t))) table))
(if
(not (null? table))
(begin
(format #t "~10s~10d~%" (caar table) (cadar table))
(format-table (cdr table)))))
 
(define (print-freq filename)
Line 2,308 ⟶ 2,304:
 
Output when reading own source:
#\( 4845
#\u 65
#\s 9
#\e 5147
#\- 19
#\m 9
#\o 1716
#\d 19
#\l 3025
#\space 9783
#\i 1715
#\c 28
#\9 1
#\f 2120
#\r 4039
#\a 5147
#\t 3936
#\) 4845
#\newline 2521
#\n 1815
#\h 1314
#\q 7
#\p 9
#\b 2016
#\j 1
#\? 43
#\k 1
#\1 4
#\+ 1
#\# 2
#\g 1
#\" 4
#\~ 3
Anonymous user