Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!MathWorks.Com!solaris.cc.vt.edu!uunet!psinntp!news.rlcn.rl.af.mil!crowter
From: crowter@AI.RL.AF.MIL (John Crowter)
Subject: Re: EQUAL question...
Message-ID: <crowter.781979970@ai.rl.af.mil>
Sender: news@news.rlcn.rl.af.mil
Nntp-Posting-Host: lestat.ai.rl.af.mil
Organization: Rome Laboratory USAF
References: <1994Oct11.141818@iowasp.physics.uiowa.edu> <37eu3a$p3l@elna.ethz.ch>
Date: Wed, 12 Oct 1994 16:39:30 GMT
Lines: 37

marti@inf.ethz.ch (Robert Marti) writes:

>In article <1994Oct11.141818@iowasp.physics.uiowa.edu>
>banks@iowasp.physics.uiowa.edu writes:
>> I am having a problem getting an correct answer for the following problem:
>> [...code deleted...]
>>/* I am trying to see if the 1st element of the list and the last
>>   element of the list are the same of a given list */
>>Any help would be greatly appreciated.

>Sounds like a homework problem ...

>Anyway, how about:

>----------
>% last(?X, +L):  X is the last element of list L
>last(X, [X]).
>last(X, [_|T]) :- last(X, T).

>% same_first_last(+L):  list L has the same first and last element
>same_first_last([X|T]) :- last(X, [X|T]).
>----------

or how about:

% using append/3 ...

append([],X,X).
append([X|R],Y,[X|Z]) :- append(R,Y,Z).

%call ...

append([X|_],[X],FirstAndLastEqualList).


John Crowter
Rome Laboratory
