0

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.

false
  • 10,264
  • 13
  • 101
  • 209
Kim Doe
  • 3
  • 1
  • 11
  • 1
    Prolog doesn't work this way. What are you actually going to obtain? What's your *goal*? – dlask Jun 15 '15 at 18:46
  • What prolog interpreter are you using? How is `random()` defined? `random()` isn't normal Prolog syntax. If you use `random/1`, you can do, `random(X), assertz(fact(X)).` – lurker Jun 15 '15 at 19:02
  • Just guessing: do you want to set the seed? See [the SICStus manual](https://sicstus.sics.se/sicstus/docs/latest/html/sicstus/lib_002drandom.html). – false Jun 15 '15 at 19:10
  • I'm using SWI-Prolog, but thanks anyway guys – Kim Doe Jun 15 '15 at 23:35

1 Answers1

1

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.

fferri
  • 18,285
  • 5
  • 46
  • 95