Closed free-variation closed 7 years ago
Moving the lambda expression in the include
to a separate variable seems to solve it:
relations_of_type(Type, Relations, RelationsOfType) :-
Includer = [Rel]>>(Rel=rel(Type, _, _)),
include(Includer, Relations, RelationsOfType).
Lambda expressions are compiled away using a generated predicate who's name is the secure hash of the term-representation of the predicate. If you load the code for the first time and you do not explicitly include library(apply)
it doesn't know include/3 is a meta-predicate and thus it will use the interpreted version. If you run it, include/3 wil be autoloaded and if your next reload it knows this is a meta-predicate.
So, there is only a bug if the generated predicate doesn't do what it is supposed to do. Note that interpreted Lambda expressions are pretty slow.
Thank you for the explanation Jan. When are lambda expressions interpreted vs compiled? When they contain variables that are not declared in the existentials and lambda var lists?
They are compiled by expand_goal/2. That means they must appear in a goal position of a predicate and must be sufficiently instantiated at compile time. As they are mostly used together with predicates from the library(apply)
, make sure to use :- use_module(library(apply)).
in such cases. That ensures the definitions of maplist, include, etc. are known.
I have a source file with the following relation:
After initially loading this all is well:
However, if I then reload the file, or issue
make
, I get an odd corruption:This is on Linux Mint 18.1, running both SWI-Prolog
dev
andstable
, i.e. 7.5.3 and 7.4.2.