From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Find the longest word in the word list file. Date: Wed, 11 Aug 2021 16:27:55 +0200 Message-ID: <871r709huc.fsf@gmx.net> References: <875ywc9j7i.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20898"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: help-gnu-emacs To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 11 16:28:21 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDpDQ-0005GH-R0 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 11 Aug 2021 16:28:20 +0200 Original-Received: from localhost ([::1]:49652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDpDO-00061g-Tp for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 11 Aug 2021 10:28:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDpD5-00061K-Qb for help-gnu-emacs@gnu.org; Wed, 11 Aug 2021 10:27:59 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:58787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDpD4-0001Sk-2B for help-gnu-emacs@gnu.org; Wed, 11 Aug 2021 10:27:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1628692075; bh=q2RT2JrukEh+EzXeNEbSNTkStCouJ7HuZy4SaaLTIe4=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=BFKvW41fV858S5n+3AzacoSCJtvd59ibP1DZ8ynu6FS6GYKOctOQEZftgr/AA9OOe 8TfaIwQEyj6xBAccZeojjKpSfuB9GPuJC4YoEzcOZ7tWGfnLRT7y5dntUbaYUrR8+j YHQrH0Cz/Ix9rAginfHDtn+Nynh+1Im4MsSFuNVM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobelfs ([92.73.76.192]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N17YY-1nEt8r2kcE-012apU; Wed, 11 Aug 2021 16:27:55 +0200 In-Reply-To: (Hongyi Zhao's message of "Wed, 11 Aug 2021 22:17:02 +0800") X-Provags-ID: V03:K1:zSFDmnp2pnXY111uqMgbKNfvHzKkaK+x95AnRDEBxWKQILAeeIh LdaeaBaiDcdj1iOPYAfF6mwQNFltA0yJZ12a16QUPnoT2WMJOked8f/Z/Fzi/+X3kJ0T65p zGULFppg80FYi8Rz+kYwtJhMuSo7kTpoi5KotS7stuWCacmzuRV8r79WZjMw46kGkQtpkl4 rEY7cciKQlbM5OdvMQZZg== X-UI-Out-Filterresults: notjunk:1;V03:K0:s3YDbQu8Ed8=:G+n/AVaGxED8gFnMWs4faK KSNnyiez+Mta3Yd9TI+XTG4q6OUp5IecxG+lwkgj+/nG6wIYqWrfJAYubOonJ1Ma3T+TCiHlm QoSrUNvsaOyrHRmTNZES7lcrgEMRH/MF9b5J26+VhrjYCvQhcq+4QkCpnPAyCqPCBd4Ico11y Go8N2/iSpM+7yjlzL8UElHM4B8J3SDj13TCEP7u5X8KsnlEcN1EVZQDf1KqOKEg+3uQB7ReqQ j97KKwKCawXaQcHDv1OFuRkAIb4HP6usWV0L8yNzIGhGIQMNCH/WWoIujfpfdY0FRsYAiopBb f7UzQm5m1LB57EfFLFvkeGSMejNfBVN46N1bLlBSDP1qQ56j3zkq+1bznC+RnzMyfOKUrcKmM pBUEOpo9uSiFnRVw9+irPNKeAQ6EwGz8+R6lap+UkkGGVsk/amek9uW8uyQimXwO4ORSsH98x IlfUpGEh5nLhpzTMI2NBEXOvNUXeWeUJnezh5BwF9Y0rh0xpqee3lKTEjwR+NC6Y2zoYlYG+7 GNPOUtEHlt3y27GxtoCW5CDCQclQxAPgESCXlLIv+s4m1AMISONr0HX5lr1lvpX6SVKGAkvWy 1hyRAbcJJQ7CQALv1jFBrqDXEn5V/aBTtJBRuDB75wJiYmWOQL55LSfJycOaUa8YsA2Hchpp5 jrcLeWtf7VIj3KCJXv41knY0CxVThfYWXn4M9fCsbaYXrW5sARCxRx68MEY8vPL/Y5AfLCvT/ sDE5oFjFwP0bVGPJnBE7du8GNYPyCueV4T6JUaSkeC7fGsNPae1J9xFdNnCHMAdMxHoM9wyS Received-SPF: pass client-ip=212.227.17.22; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:132456 Archived-At: On Wed, 11 Aug 2021 22:17:02 +0800 Hongyi Zhao wrote: > On Wed, Aug 11, 2021 at 9:58 PM Stephen Berman wrote: >> >> On Wed, 11 Aug 2021 07:14:05 +0800 Hongyi Zhao 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