[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to improve the readability of (any) LISP or any highlevel functi
From: |
Paul Rubin |
Subject: |
Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ? |
Date: |
Sat, 01 Jan 2011 22:46:08 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
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.
- How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, girosenth, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Elena, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Pascal J. Bourguignon, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Nathan, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Jan Burse, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, The Quiet Center, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Jan Burse, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, LanX, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, LanX, 2011/01/01
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Nathan, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?,
Paul Rubin <=
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, LanX, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Jerome Baum, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Paul Rubin, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, w_a_x_man, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, w_a_x_man, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, LanX, 2011/01/03
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Frank GOENNINGER, 2011/01/02
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, w_a_x_man, 2011/01/07
- Re: How to improve the readability of (any) LISP or any highlevelfunctional language to the level of FORTH ?, WJ, 2011/01/09
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Didier Verna, 2011/01/03