Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 15th, 2007, 06:34 PM
kilosi kilosi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 1 kilosi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 17 sec
Reputation Power: 0
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:

Code:
eTree1(expTree('+',
	expTree(const, 5),
	expTree('*',
	     expTree(const, 3),
	     expTree(const, 2)
	 )
     )
 ).


I have to calculate the answer, which is 11 in this case.

So I wrote this:
Code:
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).


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.

When I run the above I get this:

Quote:
?- eTree1(T), eval(T, V).
H is: expTree(+, expTree(const, 5), expTree(*, expTree(const, 3), expTree(const, 2)))
T is: []

No


expTree is not defined in the program we have been given but it has been described in comments as follows:

Quote:
Below are 3 structures that representation expression trees using Prolog.
(Op is any Prolog operator.)

expTree(Op,Lt,Rt).
expTree(const,Value).
expTree(Op,T).


My question:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Prolog Tree Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway