From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: nrichard Newsgroups: gmane.lisp.guile.user Subject: letter occurence in a text Date: Tue, 22 May 2012 07:26:09 -0700 (PDT) Message-ID: <33889562.post@talk.nabble.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1337730611 21514 80.91.229.3 (22 May 2012 23:50:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 22 May 2012 23:50:11 +0000 (UTC) To: Guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed May 23 01:50:10 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SWyq0-0007B1-LA for guile-user@m.gmane.org; Wed, 23 May 2012 01:50:00 +0200 Original-Received: from localhost ([::1]:40537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWyq0-0004T9-3j for guile-user@m.gmane.org; Tue, 22 May 2012 19:50:00 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:40958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWq2W-00040X-7o for Guile-user@gnu.org; Tue, 22 May 2012 10:26:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SWq2N-0004Fw-Pv for Guile-user@gnu.org; Tue, 22 May 2012 10:26:19 -0400 Original-Received: from sam.nabble.com ([216.139.236.26]:35167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWq2N-0004Dj-Kz for Guile-user@gnu.org; Tue, 22 May 2012 10:26:11 -0400 Original-Received: from telerig.nabble.com ([192.168.236.162]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1SWq2L-0001BW-K1 for Guile-user@gnu.org; Tue, 22 May 2012 07:26:09 -0700 X-Nabble-From: nnomekoorichard@gmail.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 216.139.236.26 X-Mailman-Approved-At: Tue, 22 May 2012 19:49:53 -0400 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9471 Archived-At: 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-tp33889562p33889562.html Sent from the Gnu - Guile - User mailing list archive at Nabble.com.