opensubscriber
   Find in this group all groups
 
Unknown more information…

m : mit-scheme-users@gnu.org 22 May 2012 • 10:28PM -0400

[MIT-Scheme-users] letter occurence in a text
by nrichard

REPLY TO AUTHOR
 
REPLY TO GROUP





hello my problem is to count occurence of letter in a text and come out with
an assoc-list like
'((a.16) (b.10) ... (z.5))
i started a fee function but they don't work so please help me

;; an alist
(define lettre '((""."") ) )
(define lettre2 '(("a". 1) ("b". 1) ("c". 1) ) )

;; this function take a key and an alist
;; add the key to the alist if it is not a space,a newline,and does not
already exist
;; update the value of the given key
(define (lettre-test x alist)
(cond ((and
           ( and (not (char=?  x #\space))(not (char=?  x #\newline)))  
           (eq? (assoc (make-string 1 x) alist) #f))  
           (set! alist
           (assoc-set! alist (make-string 1 x) 0 )))
           ((char=?  x #\space) '())
           ((char=?  x #\newline) '())
           (else
           (set! alist  
       (assoc-set! alist (make-string 1 x) (+ (assoc-ref alist
(make-string 1 x)) 1))))))

;; this function open a file
;; read the caracter and count the occurence of each character
(define (compte-char source alist)
(let ((p (open-port source)))
  (let f ((x (read-char p)))
    (cond ((eof-object? x)
        (begin
          (close-input-port p)
          '()))        
         (else
        (cons (lettre-test x alist) (f (read-char p))))))))
--
View this message in context: http://old.nabble.com/letter-occurence-in-a-text-tp33889577p33889577.html
Sent from the Gnu - MIT Scheme - Users mailing list archive at Nabble.com.


_______________________________________________
MIT-Scheme-users mailing list
MIT-Scheme-users@gnu....
https://lists.gnu.org/mailman/listinfo/mit-scheme-users

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

opensubscriber is not affiliated with the authors of this message nor responsible for its content.