0

i'm pretty new to prolog and now only the very basics and i ran into a problem

i need to write a statement line this: <cond.1> and (<cond.2> or <cond.3>)

in languages like c++ it would look something like this:

if(<cond.1> && (<cond.2> || <cond.3>)) { /*...*/ }

And i tried this in prolog:

statement(X, Y, Z, W):-condition(X,Y,Z,W), !, X <> Z or Y <> W.

And this

statement(X, Y, Z, W):-condition(X,Y,Z,W) and (X <> Z or Y <> W).

And more things that google told me. Nothing worked, and i know that this logical statement would look like this in expanded form: <cond.1> and <cond.2> or <cond.1> and <cond.3>

But this is creates a frick ton of code and makes it unreadable. i just feel there has to be a way to implement these conditions inside a parentheses. But i just dont know how and i can't find any way to do it.

ZecosMAX
  • 216
  • 1
  • 9
  • i found some info about this problem: if i write something like this `cond(X, Y) :- (X = Y).` it tell me about an error before equal sign `406 ')' or ',' expected` and this freak me out, bc how this kind of parentheses could not work? – ZecosMAX Dec 12 '19 at 15:42
  • The "or" would be a semicolon, so `;`, the "and" a comma `,`; and `X <> Z` is probably `X \= Z`. – Willem Van Onsem Dec 12 '19 at 16:20
  • @WillemVanOnsem nope. i tried this as well, only parentheses won't work for some reason – ZecosMAX Dec 12 '19 at 16:22
  • Try your problem in the online Prolog shell [SWISH](https://swish.swi-prolog.org/) – David Tonhofer Dec 13 '19 at 08:39

1 Answers1

0

The "logical or" is denoted with a semicolon (;). So your predicate would likely look like:

statement(X, Y, Z, W) :-
    condition(X,Y,Z,W),
    (X \= Z; Y \= W).

Here the \=/2 predicate [swi-doc] succeeds if it can not unify X with Z (or Y with W).

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • for `X \= Z` it says "illegal character". so with `X <> Z` it's working fine but still says `406 ')' or ',' expected` after X – ZecosMAX Dec 12 '19 at 16:27
  • @ZecosMAX: Then likely the error is located before the `statement` definition. For example you forgot a dot at the end of a clause, or a bracket, etc. – Willem Van Onsem Dec 12 '19 at 16:28
  • And not this. well, i could just dump all of my code here (but i don't think that's a good tone) i checked everything for 10 times. Everything should just work fine, but it does not. idk why. – ZecosMAX Dec 12 '19 at 16:31
  • Also my version of turbo prolog for some reason won't accept symbol '\' So `true(X) :- \+ false(X).` won't work – ZecosMAX Dec 12 '19 at 16:35
  • @ZecosMAX: this looks really strange, since `\+` is a *ISO* Prolog predicate, so that means that everything that calls itself "standardized Prolog", should support that. – Willem Van Onsem Dec 12 '19 at 16:37
  • can you advice me an implementation of prolog (for dosbox maybe) which is for sure supports everything what prolog does? – ZecosMAX Dec 12 '19 at 16:53