Hi.
The fib function is not available in Picat from the start, and it must first be defined so Picat can recognize it. There are some ways to do this:
* Generally the best way is to create a text file with the extension .pi - for example fib.pi - that contain the definition . You can then load it into the Picat REPL via the cl command:
Picat> cl(fib)
and then run it:
Picat> X=fib(10)
X = 55
If this does not work, see chapter 2 on how to run a Picat program.
Having the function defined in a Picat program makes it easier of you then want to do some more experiments, for example like this program
"""
main =>
X = fib(10),
println(X),
nl.
fib(0) = 1.
fib(1) = 1.
fib(N) = F, N>1 => F = fib(N-1)+fib(N-2).
""""
* The other way is to define the fib function directly into the REPL using the cl() function without any filename and then paste the definition:
Picat> cl
fib(0) = 1.
fib(1) = 1.
fib(N) = F, N>1 => F = fib(N-1)+fib(N-2).
<Ctrl-D to end input>
Picat> X=fib(10)
X = 55
(The exact combination to end the input depends on the operating system you are on. On Linux it's Ctrl-D and Ctrl-Z on Windows. See more on this in section "2.1.2
How to Use the Command-line Editor" ).
This works but there's no way to edit the definition in the REPL if you want to change it, but it might work to paste a corrected version using cl() again. This is why it's better to use files.
That being said, for short definitions, for example if I just want to do a quick test, this can be quite useful.
More on the REPL is in the User Guide section "2.1.2 How to Use the Command-line Editor" .
A side note: If you find that the fib function is too slow on larger values of N (say N=50), then look at chapter 7 on tabling (memoisation/caching) of the result of previous calls of a function/predicate.