From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: w_a_x_man Newsgroups: gmane.emacs.help 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) Organization: http://groups.google.com Message-ID: <8a75fa03-3728-43fb-9747-cc9c263605e8@f20g2000prn.googlegroups.com> References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <87pqsgk8v9.fsf@kuiper.lan.informatimago.com> <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com> <3bd9f0cb-a400-4332-adf2-27cddb1a2db6@l7g2000vbv.googlegroups.com> <1347a932-5751-4c20-9c4a-5594ed860ea6@35g2000prb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1293989182 4390 80.91.229.12 (2 Jan 2011 17:26:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 2 Jan 2011 17:26:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 02 18:26:17 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PZRhB-0004yh-9L for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Jan 2011 18:26:17 +0100 Original-Received: from localhost ([127.0.0.1]:49134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZRhA-0004MM-GI for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Jan 2011 12:26:16 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!f20g2000prn.googlegroups.com!not-for-mail Original-Newsgroups: comp.lang.functional, comp.lang.lisp, gnu.emacs.help, comp.lang.forth, comp.lang.prolog Original-Lines: 23 Original-NNTP-Posting-Host: 209.42.179.244 Original-X-Trace: posting.google.com 1293952488 12747 127.0.0.1 (2 Jan 2011 07:14:48 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sun, 2 Jan 2011 07:14:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f20g2000prn.googlegroups.com; posting-host=209.42.179.244; posting-account=vf5QpQoAAADgh9WOa2uZtoS1yoyJdEBw User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.80 (Windows NT 5.1; U; en) Presto/2.6.30 Version/10.63,gzip(gfe) Original-Xref: usenet.stanford.edu comp.lang.functional:69070 comp.lang.lisp:297083 gnu.emacs.help:183839 comp.lang.forth:160252 comp.lang.prolog:44001 X-Mailman-Approved-At: Sun, 02 Jan 2011 12:21:07 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78061 Archived-At: On Jan 1, 11:36=A0pm, Nathan wrote: > Well, to answer the question simply, this code will provide the > functionality you've been asking about in Ruby. > > my_list =3D [1, 1, 1, 1, 2, 3, 3, 1, 1, 4, 5, 5, 5, 5] > print my_list.reduce([]){|x, y| > =A0 if x.empty? or x[x.length-1] !=3D y then Instead of x[x.size-1], use x[-1] or x.last. > =A0 =A0 x + [y] > =A0 else > =A0 =A0 x > =A0 end > > } Another way using reduce: %w(a a a b c c a a d e e e).reduce([]){|a,x| a[-1]=3D=3Dx ? a : a<["a", "b", "c", "a", "d", "e"] This assumes nils aren't allowed in the source array.