1
votes

This is my first question and it's very important to me. I'm trying to make a simple program. I'm new in Prolog and don't know how to use logical operators, can anyone help? Thanks!

lamp(on):-energy(on).
ELSE lamp(off).

Important: I'm using SWI-Prolog.

2
Have you tried any Prolog tutorials or books? Exactly what kind of program are you trying to write and what have you tried? Is this for a class? - lurker
Try some starter resources. This site is more useful for when you have specific problems - kravits88
There is nothing in this question that makes it obvious what is it that you are trying to achieve. You could at the very least include some pseudo-code in your question! - user1812457

2 Answers

1
votes

Of course, if the possible arguments of the energy/1 predicate are the same as the possible arguments of the lamp/1 predicate, i.e. either on or off, you can simply write:

lamp(State) :-
    energy(State).

Otherwise, just follow the advice @g_a_kowalski.

1
votes

Use combination of operator ->/2 and operator ;/2:

( If -> Then ; Else )

For example:

( 10 < 20 -> print(true); print(false) )

Or

lamp(X) :- ( energy(on) -> X = on; X = off) )