From hocaoglu@ece.arizona.edu  Tue Mar 28 17:04:42 2000
Received: from ece2.ece.arizona.edu (ece2.ece.arizona.edu [128.196.29.20])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id RAA20794
	for <prolog@swi.psy.uva.nl>; Tue, 28 Mar 2000 17:04:41 +0200 (MET DST)
Received: from localhost (hocaoglu@localhost)
	by ece2.ece.arizona.edu (8.9.3/8.9.3) with ESMTP id IAA26700;
	Tue, 28 Mar 2000 08:04:51 -0700 (MST)
X-Authentication-Warning: ece2.ece.arizona.edu: hocaoglu owned process doing -bs
Date: Tue, 28 Mar 2000 08:04:51 -0700 (MST)
From: Fatih Hocaoglu <hocaoglu@ece.arizona.edu>
To: Ada Winters <diving@nehp.net>
cc: prolog@swi.psy.uva.nl
Subject: Re: Prolog examples
In-Reply-To: <3.0.6.32.20000327212221.00830610@mail.nehp.net>
Message-ID: <Pine.GSO.4.10.10003280800020.26652-100000@ece2.ece.arizona.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Mon, 27 Mar 2000, Ada Winters wrote:

> Dear Sirs,
> I need help with the following programs:
> 1.  Write a predicate dislay_list with arity 1 to display an entire list
> w/o any user prompts where each list element appears on a spearate line
> with its sequence number and it works for the empty list.
> 

display_lis(L):-display_list_aux(L,L).

display_list_aux([],_).
display_list_aux([X|K],L):-write(X),write(' '),nth1(Y,L,X),write(X),nl,
			   display_list_aux(K,L).



> 2.  Write a predicate tohead with arity 3 that will move an element to the
> head of a list:
> tohead( c, [a, b, c, d], X ).
> X = [c, a, b, d]
> tohead (c, [x, y, z], X ).
> no
> 

tohead(X,L,Z):-append(A,[X|K],L),
		append([X],A,ZZ),
		append(ZZ,K,Z).



