views:

34

answers:

1

I am attempting to learn the basics of Prolog for a class. I'm running into the seemingly simple problem of not being able to store a list within a rule and retrieve it for usage in other clauses. For example:

% These are the contents of the pl file I want to consult

% Numbers I want to process
inputList([3,2,1,0]).

% Prints out the contents of a list
printList([First | Tail]) :- 
    write(First),nl,
    printList(Tail).

What I want to do is call the following within Prolog:

?- inputList(X).
?- printList(X).

The goal is to avoid constantly entering long lists into the Prolog interpreter and instead store them in the .pl file. However, entering the commands above results in the list not being properly checked against the given clause. How can this be accomplished, preferably using the structure above to store a list {listContents([a,b,c,d]).}?

A: 

I think you need to modify your call in Prolog to

?- inputList(X), printList(X).
Juan Macek