From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!peer01.cox.net!cox.net!feed2.news.rcn.net!rcn!feed3.news.rcn.net!not-for-mail Sender: jsa@rigel.goldenthreadtech.com Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) References: <338040f8.0409230912.70e3375b@posting.google.com> From: jayessay Organization: Tangible Date: 26 Sep 2004 13:02:01 -0400 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: DXC==NLd5Jm?G7^ X-Complaints-To: abuse@rcn.com Xref: g2news1.google.com comp.lang.ada:4219 Date: 2004-09-26T13:02:01-04:00 List-Id: Eric Jacoboni writes: > Eric Jacoboni writes: > > > What about Ruby ? Much more readable than perl/python, imho. Its > > inventor claims to be inspired by Ada and Eiffel syntaxes. Actually, Ruby is closer to Lisp than either of those. > Ok, i've finally found the equivalent of while (<>) construct in Ruby, > so the initialisation of the hash is now more concise. By using 'for' > instead of iterators, the code is more Ada-ish : > > for a_file in ARGF do > for a_line in a_file do > for a_word in a_line.split(/[^A-Za-z]+/) do > count[a_word.downcase] += 1 > end # for a_word > end # for a_line > end # for a_file (defun word-count-2 (file-spec &key (wordpat (compile-pattern "[A-Za-z]+"))) (let ((count (make-hash-table :test #'equal))) (with-open-file (the-file file-spec :direction :input) (for-each line :in the-file (for-each word :in (split-string wordpat line) (incf (gethash (string-downcase word) count 0))))) (let ((topten (subseq (sort (all (w c) :in count) #'> :key 'second) 0 10))) (for-each pair :in topten (print pair))))) Just curious, do people who had "trouble" with the first version find this one as "clear" as the Ruby? Note: the part that is the same as the above Ruby is just: (with-open-file (the-file file-spec :direction :input) (for-each line :in the-file (for-each word :in (split-string wordpat line) (incf (gethash (string-downcase word) count 0))))) /Jon -- 'j' - a n t h o n y at romeo/charley/november com