% If-Then-Else statement gt(X,Y) :- X >= Y,write('X is greater or equal'). gt(X,Y) :- X < Y,write('X is smaller'). % If-Elif-Else statement gte(X,Y) :- X > Y,write('X is greater'). gte(X,Y) :- X =:= Y,write('X and Y are same').
In Prolog, use ";" for or and "," for and. gothrough([H|T], B, C):- ( (T == [] ; H == 'then') %if either the tail is an empty list or if H == "then", do the following% -> append(H,B,B), outputs(B,C) ; append(H,B,B), gothrough(T, B, C) %else% ).
I looked this up on the SWI prolog website where they defined it as. The arithmetic expression X equals Y. When reasoning over integers, replace is/2 by #=/2 to obtain more general relations.
It is Prolog-implementation specific. It refers to a successor-predicate, see this for some more info. Follow this answer to receive notifications.
If I have this function:
min(List1, List2, Output) :-
length(List1, N),
length(List2, M),
( N < M ->
Output = 'true'
; Output = 'false'
).
but what if I wanted to also check if N == M? Maybe like this:
min(List1, List2, Output) :-
length(List1, N),
length(List2, M),
( N < M ->
Output = 'true'
; ( N = M ->
Output = 'equal'
; Output = 'other'
)
).
Doesn't seem to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With