From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan Burse 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: Sun, 02 Jan 2011 02:10:45 +0100 Organization: albasani.net 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=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1293932439 24540 80.91.229.12 (2 Jan 2011 01:40:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 2 Jan 2011 01:40:39 +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 02:40:35 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 1PZCvv-00019E-Jq for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Jan 2011 02:40:31 +0100 Original-Received: from localhost ([127.0.0.1]:41917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZCvu-0006EQ-PD for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Jan 2011 20:40:30 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!t-online.de!news.albasani.net!not-for-mail Original-Newsgroups: comp.lang.functional, comp.lang.lisp, gnu.emacs.help, comp.lang.forth, comp.lang.prolog Original-Lines: 50 Original-X-Trace: news.albasani.net fDiUUzjp6AiqsDiMEfC/lb4CBE6lnWvkGw1Si0JwU76SrdN3FizTjwg3EQoZ6Q256QGLFojjUaLSUibv176qfg== Original-NNTP-Posting-Date: Sun, 2 Jan 2011 01:10:48 +0000 (UTC) In-Reply-To: <9e7a7683-a92a-4e88-a6f1-9e6a6bd2f057@z9g2000yqz.googlegroups.com> Cancel-Lock: sha1:SDkfVHtGzqKvrQp0Yqlgc34zTpE= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.1.16) Gecko/20101123 SeaMonkey/2.0.11 Injection-Info: news.albasani.net; logging-data="i8V462ZsXj8zaGFR94jBSxXlMRwk/Kx7HreAlrQ6QaR3j8bOReDWjjhMr+foytqodsfGwu99S1RHyMJd+2ycl5tNiQQodWx93/NdJeWYzPQKdv+MM2vm1VH2U2dsVVoB"; mail-complaints-to="abuse@albasani.net" Original-Xref: usenet.stanford.edu comp.lang.functional:69063 comp.lang.lisp:297071 gnu.emacs.help:183829 comp.lang.forth:160241 comp.lang.prolog:43993 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:78039 Archived-At: The Quiet Center schrieb: > %http://sites.google.com/site/prologsite/prolog-problems/1 > > % Problem 1.08 - compress consecutive duplicates into a single > % list element > > compress([], []). > compress([X,Y], [X,Y]) :- X \= Y. > compress([X,Y], [X]) :- X = Y. > > % problems writing other clauses (thanks RLa) > > compress([X,Y|Z], [X|Z1]) :- X \= Y, compress([Y|Z], Z1). > compress([X,Y|Z], Z1) :- X = Y, compress([Y|Z], Z1). > The above code does not work fully correct. Here is a counter example (try yourself): ?- compress([a],X). No In a Prolog introductory course I would anyway use: % compress(+List,-List) compress([X,X|L],R) :- !, compress([X|L],R). compress([X|L],[X|R]) :- compress(L,R). compress([],[]). No reason to use (\=)/2, which is anyway not declarative, and no reason to avoid the cut !/0. Bye P.S.: On sites.google.com I find the following solution, correct, but also avoids the cut !/0: % 1.08 (**): Eliminate consecutive duplicates of list elements. % compress(L1,L2) :- the list L2 is obtained from the list L1 by % compressing repeated occurrences of elements into a single copy % of the element. % (list,list) (+,?) compress([],[]). compress([X],[X]). compress([X,X|Xs],Zs) :- compress([X|Xs],Zs). compress([X,Y|Ys],[X|Zs]) :- X \= Y, compress([Y|Ys],Zs).