[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: |
Sun, 02 Jan 2011 13:21:54 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
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.
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, (continued)
- 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, 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/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 <=
- 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
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Tim Harig, 2011/01/03
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, rusi, 2011/01/04
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, D Herring, 2011/01/04