There are many libraries that use meta calls. For example
Bart Demoen et al. âTorâ and Ulrich Neumerkels âindexing difâ:
Tor: Extensible Search with Hookable Disjunction
https://www.swi-prolog.org/pack/list?p=tor
Many Prolog programs are unnecessarily impure
https://arxiv.org/abs/1607.01590
But the issue needs of course be also examined for call/n
and not only call/1. Currently Dogelog Player doesnât have call/n,
only call/1, so I donât know. I also donât know why it doesnât
work in formerly Jekejeke Prolog or in SWI-Prolog. In SWI-Prolog
if you create a temporary clause, last call optimization could skip
it, but you need also a mechanism to garbage collect it.
In formerly Jekejeke Prolog I create a temporary half clause,
only the body of a clause. I thought I made it so that it gets skip
and garbage collected, maybe there is a bug somewhere.
Edit 24.04.2022:
One view of last call optimization is that it shrinks the call stack,
either by reusing a clause instance frame, B-Prolog and its TOAM
architecture wrote about this, or by creating a new one, and
deleting an old one, the alternative to TOAM. You need then compaction
so that it gets permanently âskippedâ in the calls stack. It could be that
SWI-Prolog is closer to TOAM, and the reuse, the check for reuse,
that all compiled code has in SWI-Prolog, doesnât work for a meta calls.
B-Prolog the precursor of Picat, describes the approach of TOAM
as follows, in the paper here:
Unlike the call instruction which always allocates a new frame
for the callee, the last call instruction reuses the current frame if
it is a determinate frame or a choice point frame whose
alternatives have been cut off.
Dogelog Player doesnât do that, instead it is completely stackless
trampoline. And then the host language garbage collector can also
collect frames resulting from meta call compilation.
As a drawback currently Dogelog Player cannot show a stack trace
when an error is thrown. Although maybe there is a way to extract a
stack trace from the choice points that are around,
but I havent figured this out yet.