3

The execution profiler of SICStus Prolog 4.5.1 reported the following to me:

| ?- print_profile.
       insns   try/retry      called        name
----------------------------------------------------------------
                          ...
----------------------------------------------------------------
                             1769156/8845768    prolog:evaluate/2
                             7076612/8845768    prolog:evaluate2/2
    76073600     7076616     8845768        prolog:evaluate2/2
                             7076612/8845768    prolog:evaluate2/2
----------------------------------------------------------------
                          ...

Out of curiosity: what is evaluate2/2 and how can I find out which parts of Prolog code call it?

(My best guess is this: evaluate/2 and evaluate2/2 evaluate arithmetic expressions which are still variable when some (is)/2 goals are compiled...)

repeat
  • 18,496
  • 4
  • 54
  • 166

1 Answers1

4

Your guess is correct. The prolog:evaluate/2 and prolog:evaluate2/2 predicates are helpers used when the expression cannot be evaluated directly in C (or in assembly with the JIT compiler). Typically because a (sub-) expression was a variable at compile time and then a compound term at runtime.

They are also called when interpreted code (asserted or consulted) evaluates arithmetic expressions with is/2 and other predicates.

There is no way to know these things except asking the SICStus developers (like me).

Per Mildner
  • 10,469
  • 23
  • 30
  • 1
    Very helpful! Apparently, a significant part of these calls in `library(clpz)` come from convenience predicates/grammars like `X is E --> { X is E }.` which makes some code a bit more readable, albeit at some runtime costs... now it's time to figure out the other (easily avoidable) uses of `evaluate/2`! – repeat Aug 21 '19 at 17:18