🔒 Locked
a simple prolog question....
Advertisement
Original Post
i am stuck on a simple problem in my prolog
program.
in the prolog prompt type:
3 > 4.
... it produces NO
4 > 3.
... it produces YES
4 = 3.
... NO
4 = 4.
... YES
watch here:
X = X.
... X = H3
... YES
X = 3.
... X = 3
... YES
my trouble is here:
X > 3.
... ERROR while executing >/2
what i want is to make somehow a logical test,
that tells me if X is larger than a specified value,
but when X is not unified to a specific value,
the test fails(NO), not producing error.
what i want to do is somthing like:
----------
is_this_larger_than_three(Value):-
Value > 3.
----------
so that:
is_this_larger_than_three(5).
... YES
is_this_larger_than_three(2).
... NO
is_this_larger_than_three(_).
... NO [not an error, as it does to me]
guess there must be a way to know that
Value , is unified or not,
and if its not unified it fails.
smthn like:
-----------
is_this_larger_than_three(Value):-
is_this_unified(Value), %how to do this?!?!
Value > 3.
-----------
[edited by - zaidgs on May 5, 2004 6:47:58 AM]
No: Unification in Prolog
Try that (untested) code.
[edited by - MDI on May 4, 2004 5:04:18 PM]
is_larger_than(X, _) :-
\+ ground(X),
write("\n\n X is not unified\n\n").
is_larger_than(X, Y) :-
ground(X),
X > Y.
Try that (untested) code.
[edited by - MDI on May 4, 2004 5:04:18 PM]
i tried,
------------
is_this_larger_than_three(Value):-
ground(Value),
Value > 3.
------------
it always fails, because ground
is not defined,
i traced it and it says:
No clauses for user:ground/1
so guess this "ground()" is
NOT a predicate in prolog !! :S
[edited by - zaidgs on May 5, 2004 7:02:36 AM]
------------
is_this_larger_than_three(Value):-
ground(Value),
Value > 3.
------------
it always fails, because ground
is not defined,
i traced it and it says:
No clauses for user:ground/1
so guess this "ground()" is
NOT a predicate in prolog !! :S
[edited by - zaidgs on May 5, 2004 7:02:36 AM]
Hmm. Are you using SWI Prolog ?
quote:
Original post by antareus
Guess what my teach called "bound" is really called "unification."![]()
well, i learnt the correct term because
i learnt prolog from tutorial that comes
with this amzi prolog. :D
i got SWI prolog, but didnt find it
comfortable. (probably because it has
no good IDE).
i have submitted my question to
technical support forums of amzi,
asking if a synonym of ground() is
available in amzi.
thanks for your help guys.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement