help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find the longest word in the word list file.


From: Stephen Berman
Subject: Re: Find the longest word in the word list file.
Date: Wed, 11 Aug 2021 16:27:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

On Wed, 11 Aug 2021 22:17:02 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:

> On Wed, Aug 11, 2021 at 9:58 PM Stephen Berman <stephen.berman@gmx.net> wrote:
>>
>> On Wed, 11 Aug 2021 07:14:05 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>>
>> > I have an English word list file that stores words in a
>> > one-word-per-line format. Now I want to find the longest word in the
>> > word list file. For example, I can use standard UNIX tools to
>> > accomplish this with the following simple commands:
>> >
>> > $ awk '$0 ~ /^[[:alpha:]]+$/ { print $0, length($0) }'
>> > american-english-exhaustive | \
>> > sort -k2n | tail -1
>> > Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch 58
>> >
>> > But in Emacs, what is the elisp implementation for the above task?
>>
>> Here's another way.  Say e.g. the following is the buffer with your list
>> of words:
>>
>> Theory
>> and
>> Simulation
>> of
>> Materials
>>
>> First do this:
>>
>> (setq l
>> '(Theory
>> and
>> Simulation
>> of
>> Materials))
>>
>> Evaluate the preceding sexp, then evaluate the following sexp:
>>
>> (car (sort l (lambda (a b)
>>                (> (length (symbol-name a)) (length (symbol-name b))))))
>
> Good. A bubble sorting, IIRC.

Actually, AFAIK the Emacs `sort' function implements a merge sort.

Steve Berman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]