Execution Goal Limit / 6 Compile Only

SICStus Prolog has a hook for expanding the target: goal_expansion/6 , which is called both at compile time and at run time during metacalling. These challenges incur some run-time overheads that slow down metacaling. The purpose of my expansion is only optimization. Thus, semantically, goals and extended goals are equivalent.

How to disconnect such calls at runtime?

(It seems that I would have to cancel goal_expansion/6 , which looks a little rude to me, and also makes it difficult to recompile easily ).

+5
source share
2 answers

The idiomatic way is to load only compile time code with load_files/3 with the when(compile_time) 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 goal_expansion/5 definition is also not ideal (since it will disappear if you then recompile). This is not as bad / red as it seems: goal_expansion/5 for each module, so you can cancel it without fear that you will destroy some functions in some other module.

+5
source

A prolog_load_context/2 would be to call the predicate prolog_load_context/2 . Sort of:

 goal_expansion(...) :- prolog_load_context(source, _), % compile-time; expand the goal ... . 

The predicate prolog_load_context/2 succeeds only at compile time.

+4
source

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


All Articles