Search code examples
prologprolog-assert

How can I call a function random inside other function in prolog?


I'm trying to call the random function inside another function. For example I want to do this assert(fact(random()). But it does not work. How can I insert a random number this way? Thanks.


Solution

  • In prolog there is no concept of functions like you are trying to do in your code. You should do:

    random(N), assert(fact(N))
    

    I recommend reading at least first two chapters Learn Prolog Now! to better understand search and unification.