prolog - making a difference in X and a atom -


i'm searching solution this. user can use my_predicate(x) or my_predicate(item).

i want achieve both gives different output. have check if it's x or item.

i know item can checked this: atom(item) how can check on x .

roelof

edit 1. weird, on swi-prolog site wont work.

my_predicate(x) :-     var(x) ,    write("here name typed in").  my_predicate(x) :-     nonvar(x) ,    write("here x typed in"). 

var/1 it's simplest metaprogramming tool available in prolog, since allows change program behaviour depending on such fundamental property instantiation of clause' variable.

i sometime use construct

some_applicative_code(x) :-   ( nonvar(x) ; x = some_default_value ),   ... 

to have kind of default value arguments, testing purpose.

calling ?- some_applicative_code(_). x bind some_default_value.

from edited post, seems inverting logic. expect

my_predicate(x) :- nonvar(x) , write("here name typed in"). my_predicate(x) :- var(x) , write("here x typed in"). 

edit here test

1 ?- my_predicate(_). here x typed in true.   2 ?- my_predicate(carlo). here name typed in true . 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -