February 15th, 2007, 06:34 PM
Prolog Tree Question
I am trying to write a prolog program for one of my classes. I have a question on how to do something.
I am given this:
I have to calculate the answer, which is 11 in this case.
So I wrote this:
This clearly doesn't work. My problem is that I need to somehow get at what Tree is and do the operations on it, like plus or minus.
eval(Tree, V):- display([Tree]).
display():-write('End of the line').
display([H|T]):-write('H is: '), write(H), nl, write('T is: '), write(T),nl, display(H).
When I run the above I get this:
expTree is not defined in the program we have been given but it has been described in comments as follows:
So I'm not sure if I have to write expTree or if it is somewhere in the depths of Prolog itself.
Then I have to figure out how to go down the expTree. The only way I know how to go down things is with lists. But this is not a list. So I'm not really sure where to begin and what to be looking at. Once I am pointed in a right direction the I think I will be able to make some headway.
Thank you for any help.