jeudi 29 mars 2018

Prolog - Custom 'if-then-else'

I'm experimenting with Prolog and tried to make my own "if-then-else" method, so that I don't use the -> ; method, for experimenting's sake. My goal is to make it so that there can be nested ifs and elses in my code if required. Thus far I have got this:

ifthenelse(_, G, G):- G.    %no matter the condition, the goals are the same
ifthenelse(true,G,_):- G.   %if
ifthenelse(false,_,G):- G.  %else

I think my way hardly seems correct. How can I make my own ifthenelse/3 properly?

Thank you

Aucun commentaire:

Enregistrer un commentaire