Home > Archive > Prolog > February 2005 > Writing functions for If-else statement in PROLOG
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Writing functions for If-else statement in PROLOG
|
|
|
| Hi, I want to write a function in prolog for the if-else statement.
For ex,
if-instantiated( X,X) else if-instantiated (Y,Y) else if-instantiated(
X^Y, concat(X,Y):-
If the attribute X is instantiated( holds some
value) then write X, else if the attribute Y holds some value then write
Y, else if both the attributes X and Y hold some values, then append X
and
Y and write them.
I know how to write the concat function. But I am unaware of writing the
function for the above if-else rule. please help me.
Thanks in advance,
SUDHA.P
| |
| Jan Burse 2005-02-13, 8:59 am |
| show(X,Y) :- \+var(X), var(Y),
write('x:'), write(X).
show(X,Y) :- var(X), \+var(Y),
write('y:'), write(Y).
show(X,Y) :- \+var(X), \+var(Y),
write('x:'), write(X), write('y:'), write(Y).
sudha wrote:
> Hi, I want to write a function in prolog for the if-else statement.
> For ex,
> if-instantiated( X,X) else if-instantiated (Y,Y) else if-instantiated(
> X^Y, concat(X,Y):-
> If the attribute X is instantiated( holds some
> value) then write X, else if the attribute Y holds some value then write
> Y, else if both the attributes X and Y hold some values, then append X
> and
> Y and write them.
>
> I know how to write the concat function. But I am unaware of writing the
> function for the above if-else rule. please help me.
> Thanks in advance,
> SUDHA.P
>
>
| |
|
| X and Y would not be "attributes". From your question, i think you may be
having problems with the concept of logical variable.
Variables' scope is the one clause in which they appear.
Although there are occasions when a prolog programmer will want to know if a
variable is instantiated, that should be considered "unusual".
also, if A then B else C in prolog is expressed A -> B;C
but this is just syntactic sugar for
....:-A,B...
....:-C,...
Of course, here A, B, C must be prolog terms.
Walter
"sudha" <navred@rediffmail.com> wrote in message
news:efe3d3e9f55e233979c988cebaae5196@lo
calhost.talkaboutprogramming.com...
> Hi, I want to write a function in prolog for the if-else statement.
> For ex,
> if-instantiated( X,X) else if-instantiated (Y,Y) else if-instantiated(
> X^Y, concat(X,Y):-
> If the attribute X is instantiated( holds some
> value) then write X, else if the attribute Y holds some value then write
> Y, else if both the attributes X and Y hold some values, then append X
> and
> Y and write them.
>
> I know how to write the concat function. But I am unaware of writing the
> function for the above if-else rule. please help me.
> Thanks in advance,
> SUDHA.P
>
>
|
|
|
|
|