[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: |
w_a_x_man |
Subject: |
Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ? |
Date: |
Sat, 1 Jan 2011 23:14:47 -0800 (PST) |
User-agent: |
G2/1.0 |
On Jan 1, 11:36 pm, Nathan <nbeen...@gmail.com> wrote:
> Well, to answer the question simply, this code will provide the
> 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
Instead of x[x.size-1], use x[-1] or x.last.
> x + [y]
> else
> x
> end
>
> }
Another way using reduce:
%w(a a a b c c a a d e e e).reduce([]){|a,x| a[-1]==x ? a : a<<x}
==>["a", "b", "c", "a", "d", "e"]
This assumes nils aren't allowed in the source array.
- 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 ?, 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, 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 <=
- 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
- Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?, Tim Harig, 2011/01/04