prologsicstus-prolog

Internal predicates evaluate/2 and evaluate2/2


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...)


Solution

  • 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).