define (mathematical) function in prolog?
I know prolog (programming in logic) is all about returning true and
false, and that a function is something which returns anything from lists,
to numbers, to boolean values. Initially it doesn't seem that prolog has
the concept of functions but instead relies on unification, YET you can do
stuff like:
?- X is log(42).
X = 3.7376696182833684.
So it seems that there exists functions?, or is this really just some sort
of syntactic sugar hiding the unification part?
And if it really is just syntactic sugar, then how would I go about if I
wanted to define a mathematical 'function' like log2?
Of course I can use unification:
log2(X,Result) :- Result is log(X)/log(2).
But say I want to use the 'syntactic sugar function style' so I can write:
?- X is log2(8).
X = 3.0.
How can I do that in prolog?
No comments:
Post a Comment