[m-users.] Trying to understand a predicate for calculating Fibonacci numbers

Tomas By tomas at basun.net
Thu Nov 9 10:53:20 AEDT 2017


> On November 9, 2017 at 12:15 AM zeldangit <zeldangit at gmail.com> wrote:
> So I am trying to understand the following code. How is X = A + B searched
> for? So A + B has to add up to X, which is passed to the function, but
> there is no explanation of how Mercury discovers these variables that add
> up to X.

It's a bit difficult to understand exactly what you mean here. First I thought you were not familiar with recursion, but perhaps it is the difference between function and procedure that is not clear to you.

A and B are output parameters of the procedure calls. Then X is calculated.


> Also, should I read a Prolog book to have a better grasp of Mercury?

It's probably the best way to learn it.

/Tomas


More information about the users mailing list