From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "WJ" Newsgroups: gmane.emacs.help Subject: Re: How to improve the readability of (any) LISP or any highlevelfunctional language to the level of FORTH ? Date: 9 Jan 2011 10:41:05 GMT Organization: NewsGuy - Unlimited Usenet $19.95 Message-ID: References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <87pqsgk8v9.fsf@kuiper.lan.informatimago.com> <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1294573235 25303 80.91.229.12 (9 Jan 2011 11:40:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 9 Jan 2011 11:40:35 +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 09 12:40:27 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 1PbtdL-0001v0-5v for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Jan 2011 12:40:27 +0100 Original-Received: from localhost ([127.0.0.1]:44654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PbtdK-0004cC-KT for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Jan 2011 06:40:26 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!enews6 Original-Newsgroups: comp.lang.functional, comp.lang.lisp, gnu.emacs.help, comp.lang.forth, comp.lang.prolog Original-Followup-To: comp.lang.functional Original-Lines: 34 Original-NNTP-Posting-Host: p501c9d345f9d5a74f41bc0c0bce3e93e74a0a8f491dd46604b3a1a6d25d0b64c.newsdawg.com User-Agent: XanaNews/1.18.1.6 X-Antivirus: avast! (VPS 110108-1, 01/08/2011), Outbound message X-Antivirus-Status: Clean Original-Xref: usenet.stanford.edu comp.lang.functional:69171 comp.lang.lisp:297448 gnu.emacs.help:184138 comp.lang.forth:160451 comp.lang.prolog:44068 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:78315 Archived-At: w_a_x_man wrote: > On Jan 1, 5:56 pm, The Quiet Center wrote: > > > How would you code this simple list compression problem in Ruby: > > > > 1.08 (**) Eliminate consecutive duplicates of list elements. > >     If a list contains repeated elements they should be replaced > > with a single copy of the element. The order of the elements should > > not be changed. > > > >     Example: > >     ?- compress([a,a,a,a,b,c,c,a,a,d,e,e,e,e],X). > >     X = [a,b,c,a,d,e] > > > > (defun compress (stuff) > (mapcon #'(lambda (x) > (if (and (> (length x) 1) (eql (car x) (cadr x))) > nil > (list (car x)))) > stuff)) MAPCON works quite well for this. Tweeked: (defun compress (stuff) (mapcon #'(lambda (x) (if (and (rest x) (eql (first x) (second x))) nil (list (first x)))) stuff))