Article View: comp.lang.functional
Article #1148Re: How to improve the readability of (any) LISP or any highlevelfunctional language to the level of FORTH ?
From: WJ
Date: Sun, 09 Jan 2011 10:41
Date: Sun, 09 Jan 2011 10:41
33 lines
2714 bytes
2714 bytes
w_a_x_man wrote:
> On Jan 1, 5:56�pm, The Quiet Center <thequietcen...@gmail.com> 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))
Technical Details
Message-ID:
<igc3c102ul0@enews6.newsguy.com>Path:
arc1-ca.pugleaf.net!g2news2.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!enews6References:
<80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <87pqsgk8v9.fsf@kuiper.lan.informatimago.com> <ca15d8c3-86db-46fd-b35f-1a2596475769@n32g2000pre.googlegroups.com> <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com> <fd19f2c5-30a8-4f24-9104-b8038e9d1a67@l32g2000yqc.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 107f24,1641de092071599d X-Google-NewGroupId: yes X-Google-Thread: f4fd2,1641de092071599d X-Google-NewGroupId: yes X-Google-Thread: 103b8b,1641de092071599d X-Google-NewGroupId: yes X-Google-Thread: fd7c9,1641de092071599d X-Google-NewGroupId: yes X-Google-Thread: f907c,1641de092071599d X-Google-NewGroupId: yes X-Google-Attributes: gid4e63bbc566,gidf85ca024c1,gid39ae015015,gid2832dde05d,gidee3de009bc,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: arc1-ca.pugleaf.net!g2news2.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 From: "WJ" <w_a_x_man@yahoo.com> Newsgroups: comp.lang.functional,comp.lang.lisp,gnu.emacs.help,comp.lang.forth,comp.lang.prolog Subject: Re: How to improve the readability of (any) LISP or any highlevelfunctional language to the level of FORTH ? Followup-To: comp.lang.functional Date: 9 Jan 2011 10:41:05 GMT Organization: NewsGuy - Unlimited Usenet $19.95 Lines: 34 Message-ID: <igc3c102ul0@enews6.newsguy.com> References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <87pqsgk8v9.fsf@kuiper.lan.informatimago.com> <ca15d8c3-86db-46fd-b35f-1a2596475769@n32g2000pre.googlegroups.com> <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com> <fd19f2c5-30a8-4f24-9104-b8038e9d1a67@l32g2000yqc.googlegroups.com> NNTP-Posting-Host: p501c9d345f9d5a74f41bc0c0bce3e93e74a0a8f491dd46604b3a1a6d25d0b64c.newsdawg.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit User-Agent: XanaNews/1.18.1.6 X-Antivirus: avast! (VPS 110108-1, 01/08/2011), Outbound message X-Antivirus-Status: Clean