For Programmers: Free Programming Magazines  


Home > Archive > Prolog > March 2004 > Help With append/3 please









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help With append/3 please
Jeff Gaines

2004-03-27, 12:10 am

I am very new to Prolog.
I am trying to modify a 'hanoi' solution so that it returns the moves
in a list.

I have written this:

hanoi(N, [L]) :-
move(N, [L], left, centre, right).

move(0, [L], _, _, _) :- !.

move(N, [L], A, B, C) :-
M is N-1,
move(M, [L], A, C, B),
append([L], [A, B], Temp),
append([L], [Temp], L),
move(M, [L], C, B, A).

append([],X,X).
append([H|T1],X,[H|T2]) :-
append(T1,X,T2).

I am running into a nesting problem and get the following error:
Output term nested too deep, possible cyclic term or increase .cfg
outputdepth
While executing: write_/3

I am used to C Sharp where you can do:

string strWhole = strWhole + strAdd;

but I am beginning to think I can't do this in Prolog.

Guidance would be appreciated, I want the result in a list rather than
printing it as I want to capture it in the Sharp prog it is called
from.

--
Jeff Gaines Damerham Hampshire UK

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com