What is the difference between calling / 1 and a normal sentence?

If I have:

run(X) :- X. 

What's the difference between:

 ... :- ..., call(Y). 

and:

 ... :- ..., run(Y). 
+5
source share
1 answer

If you have:

  run (X): - X.

then you can see that this is equivalent to using call/1 explicitly through

  ? - listing (run / 1).
 run (A): -
         call (A) .

It follows that call(X) also declaratively equivalent to run(X) . However, if your Prolog compiler does not perform any kind of insertion, using call/1 directly is almost certainly at least very, very slightly more efficient than calling run/1 , and call call/1 .

As food for thought, think of cases like run(!) , And how generally use ! in meta-calls can affect programs if X not equivalent to call(X) .

+5
source

Source: https://habr.com/ru/post/1275204/


All Articles