In SICStus Prolog, there is a hook for expanding a goal: goal_expansion/6
which is called both at compile time and at runtime during metacalling. These calls incur quite some runtime overhead which slows down metacalling. The purpose of my expansion is optimization only. So semantically the goals and expanded goals are equivalent.
How can I disable such calls at runtime?
(It seems I would have to abolish goal_expansion/6
which looks a bit crass to me. It would also hamper lightweight recompilation).
The idiomatic way is to load the compile-time-only code using load_files/3
with option when(compile_time)
. Unfortunately, this does not help if you want to (re)compile in the same process in which you then run your code.
Using abolish
to remove the definition of goal_expansion/5
is also not ideal (since it will be gone if you then re-compile). It is not as bad/crass as it seems, though: goal_expansion/5
is per module, so you can abolish it without worrying that you destroy some functionality in some other module.
A workaround would be to call the prolog_load_context/2
predicate.
Something like:
goal_expansion(...) :-
prolog_load_context(source, _),
% compile-time; expand the goal
... .
The prolog_load_context/2
predicate only succeeds at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With