The context is a system of predicates: rules and facts, that together determine an amount to be paid to a client, depending on his situation. Most rules and facts are known at compile time, but facts about a specific situation are only known at runtime, when processing a pay out request. I know how to program a system in Mercury in the case that all predicates are known at compile time (i.e. are part of the source code), but I don't know how to introduce predicates at runtime. Is it possible to write a function that constructs a predicate with the given parameters and then be able to use the constructed predicate as part of the context against which amounts are calculated?
I am not sure exactly what your question is.
If by "construct a predicate with the given parameters", you are asking whether you can construct a closure that contains a reference to a predicate in the originally compiled program and a list of values for its initial arguments that are constructed at runtime, then the answer is "yes, you can do that".
If you mean whether you can construct at runtime a predicate whose code is NOT part of the originally compiled program, then the answer is "no, you can't do that" in Mercury. However, it is possible to work around this, by
However, this method is not recommended for anyone who doesn't have an implementor's understanding of how the Mercury implementation works.