From: nrichard <nnomekoorichard@gmail.com>
To: Guile-user@gnu.org
Subject: letter occurence in a text
Date: Tue, 22 May 2012 07:26:09 -0700 (PDT) [thread overview]
Message-ID: <33889562.post@talk.nabble.com> (raw)
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.
next reply other threads:[~2012-05-22 14:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-22 14:26 nrichard [this message]
2012-05-22 23:57 ` letter occurence in a text Mark Skilbeck
2012-05-23 13:57 ` gregory benison
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33889562.post@talk.nabble.com \
--to=nnomekoorichard@gmail.com \
--cc=Guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).