3.22 Define the operators 'if', 'then', 'else' and ':' so that the following becomes a legal term:...

Question:

3.22 Define the operators 'if', 'then', 'else' and ':' so that the following becomes a legal term: if X > Y then Z := X else Z := Y Choose the precedences so that 'if' will be the principal functor. Then define the predicate 'if' as a small interpreter for a kind of 'if-then-else' statement of the form if Vall > Val2 then Var := Val3 else Var := Val4 where Vall, Val2, Val3 and Val4 are numbers (or variables instantiated to numbers) and Var is a variable. The meaning of the 'if' predicate should be: if the value of Val1 is greater than the value of Val2 then Var is instantiated to Val3, otherwise to Val4. Here is an example of the use of this interpreter:

?- X = 2, Y = 3, X=2 Y = 3 Z=8 Val2 is 2*X, Val4 is 4*X, if Y > Val2 then Z:= Y else Z:= Val4, if Z> 5 then W := 1 else W := 0. W=1 Val2 = 4 Val4=8

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: