🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #1206

Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?

#1206
From: Paul Rubin
Date: Sun, 02 Jan 2011 21:21
25 lines
2645 bytes
LanX <lanx.perl@googlemail.com> writes:
>>    main = print [head xs | xs <- group my_list]
>
> does this really produce the desired output?
> Will the second 1 really be printed?

Yes.  "group" is a very useful function, that transforms a list into a
list-of-lists which collapses identical elements:

    group [1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5]

is

    [[1,1,1,1], [2], [3,3], [1,1], [4], [5,5,5,5]]

The list comprehension 

     [head xs | xs <- group my_list]

simply collects the first element of each of those sub-lists.

There is also groupBy, which lets you supply your own equality
predicate.  If there's not already a Lisp library similar to Python's
itertools module and Haskell's List module, it's probably worth writing
one.
Technical Details
Message-ID: <7xsjxbm26l.fsf@ruckus.brouhaha.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.brown.octanews.com.POSTED!not-for-mail
References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <87pqsgk8v9.fsf@kuiper.lan.informatimago.com> <ca15d8c3-86db-46fd-b35f-1a2596475769@n32g2000pre.googlegroups.com> <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com> <aa0e6de9-26c7-4a98-93af-24d0188a3506@m35g2000vbn.googlegroups.com> <3bd9f0cb-a400-4332-adf2-27cddb1a2db6@l7g2000vbv.googlegroups.com> <1347a932-5751-4c20-9c4a-5594ed860ea6@35g2000prb.googlegroups.com> <7x8vz3vm4v.fsf@ruckus.brouhaha.com> <ce0f5c3b-bc71-4868-8d2b-5495583ccfa8@w18g2000vbe.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 107f24,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: f4fd2,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: 103b8b,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: fd7c9,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: f907c,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Attributes: gid4e63bbc566,gidf85ca024c1,gid39ae015015,gid2832dde05d,gidee3de009bc,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.brown.octanews.com.POSTED!not-for-mail
From: Paul Rubin <no.email@nospam.invalid>
Newsgroups: comp.lang.functional,comp.lang.lisp,gnu.emacs.help,comp.lang.forth,comp.lang.prolog
Subject: Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?
References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com>
 <87pqsgk8v9.fsf@kuiper.lan.informatimago.com>
 <ca15d8c3-86db-46fd-b35f-1a2596475769@n32g2000pre.googlegroups.com>
 <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com>
 <aa0e6de9-26c7-4a98-93af-24d0188a3506@m35g2000vbn.googlegroups.com>
 <3bd9f0cb-a400-4332-adf2-27cddb1a2db6@l7g2000vbv.googlegroups.com>
 <1347a932-5751-4c20-9c4a-5594ed860ea6@35g2000prb.googlegroups.com>
 <7x8vz3vm4v.fsf@ruckus.brouhaha.com>
 <ce0f5c3b-bc71-4868-8d2b-5495583ccfa8@w18g2000vbe.googlegroups.com>
Date: Sun, 02 Jan 2011 13:21:54 -0800
Message-ID: <7xsjxbm26l.fsf@ruckus.brouhaha.com>
Organization: Nightsong/Fort GNOX
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock: sha1:OeHh8BCCbEcggsqi3nu+m/GPMuk=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 25
NNTP-Posting-Date: 02 Jan 2011 15:21:57 CST
X-Complaints-To: abuse@octanews.net