Article View: comp.lang.functional
Article #1198Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?
From: Frank GOENNINGER
Date: Sun, 02 Jan 2011 14:07
Date: Sun, 02 Jan 2011 14:07
55 lines
3566 bytes
3566 bytes
The Quiet Center <thequietcenter@gmail.com> writes:
> On Jan 1, 11:08�am, Nathan <nbeen...@gmail.com> wrote:
>> If you want a easy to read self-documenting functional language, look
>> into Ruby. I know personally that Ruby syntax was a big turn off to me
>> for several weeks (kind of like Lisp) but once you learn it, it
>> becomes the easiest to read of any programming language I've ever
>> experimented with. No contest.
>>
>
> Well, Python was chosen over Ruby for MIT's rework of their intro to
> cs course because Python is multi-paradigm, whereas Ruby claims
> everything is an object.
>
> 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]
>
>> Matz himself admitted that �...Ruby is a bad rip-off of Lisp... But it
>> is nicer to ordinary people.�
>
> yeah I guess the LOOP macro is where I got stuck in doing Lisp.
Simple:
? (defun compress (list)
(let ((last-element)
(result))
(loop for element in list
when (not (equal last-element element))
do
(progn
(setq last-element element)
(push element result)))
(reverse result)))
COMPRESS
? (setq list (list 'a 'a 'a 'a 'b 'c 'c 'a 'a 'd 'e 'e 'e 'e))
(A A A A B C C A A D E E E E)
? (compress list)
(A B C A D E)
'compress can be done in much more terse way in Lisp but this is just an
example using the Loop macro.
Frank
Technical Details
Message-ID:
<m2tyhr9z7d.fsf@ccde007.de.goenninger.net>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder.news-service.com!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<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>Show Full Headers
Complete Article Headers
X-Google-Thread: 103b8b,1641de092071599d X-Google-NewGroupId: yes X-Google-Attributes: gid39ae015015,domainid0,public,usenet X-Google-Language: ENGLISH,CP1252 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!feeder.news-service.com!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 02 Jan 2011 08:07:35 -0600 Followup-To: comp.lang.functional 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 highlevel functional language to the level of FORTH ? From: Frank GOENNINGER <dg1sbg@googlemail.com> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) 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> Date: Sun, 02 Jan 2011 15:07:02 +0100 Message-ID: <m2tyhr9z7d.fsf@ccde007.de.goenninger.net> Cancel-Lock: sha1:SsYN1ZQnYOxsIf+bzArMLbj420A= MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Lines: 55 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-4Nx4VWkNc8b8tl9wFDqaW++jrUFVzN+RQZ0S3DddNz/O+q0FvNMXPvZDk9oVHuXbMpYWh/0e8eeksRq!CRNl+4YsSYIoNNcl9pNsgKQ2iZBONAFpme2rKBkweU+fuW2WqFM2ewGnvQ/QyS79za6z X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3220