开发者

How can I insert an additional argument after the last argument in a prolog procedure?

I am new to learning prolog, and I want to know, if we have some procedure like

father("Nic","Adam").  

and I want to write a function that it will add new value to this

father("Nic","Adam","something"..) 

how can开发者_如何学编程 I do this? Using list? Or what?


Quick answer: You don't want to do that.

Longer answer: The father/2 predicate has a certain meaning, namely that for father(X,Y) X is the father of Y. A father/3 predicate is a different thing altogether. What do you want to achieve with that third argument? Normally, you use additional rules, which derive things from the father/2 predicate, or even resolve it to a father/3 argument.

The main question remains: what's the purpose of the third argument? If you want your resolution to work for certain specific 3rd arguments based on the existance of a corresponding father/2 predicate for example, you could do father(X, Y, 'something') :- father(X,Y) which will succeed if you have a corresponding father/2 fact.

PS: Do learn your terminology. In Prolog we don't speak of procedures and we don't write functions. Instead we have predicates, facts, rules, ...

PPS: I am not sure which Prolog implementation you are using, but you might want to use 'something' instead of "something". The latter usually creates a list of character codes, not a string:

?- X = 'some'.
X = some.

?- X = "some".
X = [115, 111, 109, 101].


Simply writing

father(nic, adam). 

As a predicate already defines it. It is like stating a fact: you declare that father(nic, adam) is true, then you can execute the following with these expected results :

?- father(nic, adam).
Yes

?- father(nic, X).
X = adam
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜