Subject: Re: Prolog examples

From: Fatih Hocaoglu <[email-masked]>
Date: Tue, 28 Mar 2000 08:04:51 -0700 (MST)

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).