Skip to main content
gamedev.net
🔒 Locked

a simple prolog question....

Started by zaidgs 8 replies 500+ views
Original Post
zaidgs
zaidgs
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]
antareus
antareus
is_this_larger_than_three(X) :- ground(X), X > 3.

Wait, what are you talking about, "unified?" Do you mean "undefined?" Try using ground() to check if variables are bound.

[edited by - antareus on May 4, 2004 4:53:18 PM]
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
zaidgs
zaidgs
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]
zaidgs
zaidgs
no i am using amzi prolog (6.2.14) [www.amzi.com]



[edited by - zaidgs on May 4, 2004 5:13:15 PM]
antareus
antareus
Guess what my teach called "bound" is really called "unification."
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
zaidgs
zaidgs
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.

zaidgs
zaidgs
i got this answer:

----------
The predicates var(X) and nonvar(X) succeed, resp. if X is unbound or bound.
----------

it worked fine for me. thanks all.

just another quick question:

is:

some_test:-
test1;
test2.

equivalent to:

some_test:-
test1.
some_test:-
test2.


?!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.