🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #1194

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

#1194
From: Paul Rubin
Date: Sun, 02 Jan 2011 06:46
25 lines
2077 bytes
Nathan <nbeenken@gmail.com> writes:
> functionality you've been asking about in Ruby.
>
> my_list = [1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5]
> print my_list.reduce([]){|x, y|
>   if x.empty? or x[x.length-1] != y then
>     x + [y]
>   else
>     x
>   end
> }

That is pretty ugly; in Haskell you could write

   my_list = [1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5]
   main = print [head xs | xs <- group my_list]

That uses a Python-like list comprehension since you mentioned Python,
but more idiomatic would be

   my_list = [1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5]
   main = print . map head . group $ my_list

There is probably a function like "group" available in Ruby.  Python has
itertools.groupby but it's a little bit brittle.
Technical Details
Message-ID: <7x8vz3vm4v.fsf@ruckus.brouhaha.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.beige.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>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.beige.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>
Date: Sat, 01 Jan 2011 22:46:08 -0800
Message-ID: <7x8vz3vm4v.fsf@ruckus.brouhaha.com>
Organization: Nightsong/Fort GNOX
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock: sha1:Jj7+8Iy+x35L/Li99937t+MqC4o=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 25
NNTP-Posting-Date: 02 Jan 2011 00:46:13 CST
X-Complaints-To: abuse@octanews.net