How does meta_predicate numeric meta argument specifier modify the code or execution engine to include the module?

For meta_predicate with a non-numeric meta argument specifier such as ? the module is not passed, e.g
This calll display_list(nodes) is received as display_list(nodes).

For meta_predicate with a numeric meta argument specifier such as 1 the module is passed, e.g.
This calll display_list(nodes) is received as display_list(example:nodes).

I thought that maybe the code was modified using program transformation but a listing of the predicate showed no changes.

How does meta_predicate numeric meta argument specifier modify the code or execution engine to include the module between the passing and receiving of the goal predicate? Or is a listing not showing the changes, or is it something else?


EDIT

Since there is no reply at present asked ChatGPT

ChatGPT

The behavior you describe likely pertains to a Prolog programming language, in which “meta_predicate” is a directive used to specify the properties of a predicate. The use of a non-numeric or numeric meta argument specifier specifies the treatment of the argument(s) in the predicate call.

In Prolog, when a predicate is defined as meta_predicate with a non-numeric meta argument specifier (e.g. “?”), it means that the argument is passed unmodified to the predicate’s body. On the other hand, when a predicate is defined with a numeric meta argument specifier (e.g. “1”), it means that the argument is passed as a closure (i.e. a term that encapsulates a goal and its environment).

A listing of the predicate would not show any changes, as the directive “meta_predicate” does not modify the predicate’s definition, but rather its behavior. The use of meta_predicate affects the execution engine by changing the way arguments are passed to the predicate, as described above.

Still does not answer my question with concrete details and seems to hint that SWI-Prolog should be in the user post to help ChatGPT put meta_predicate in context of a specific Prolog.

It is not a brilliant answer … Qualification happens on meta-specifiers that indicate that the argument is module-sensitive. Basically that are all specifiers except for *, ?, -, +. So, numeric means call/N+1, // calls a DCG, ^ a setof/bagof/… goal and : says the argument is not directly involved in a call, but is module sensitive.

Thanks, not the kind of answer I was seeking.

What I am looking for is the code (Prolog, C, …) that adds the module name to the goal. I don’t know if that is done during the compilation, at run time, or something else.

Traditionally Prolog systems in the Quintus family do that at compile time. SWI-Prolog does it at runtime. It is done by VM instructions that are added to the “supervisor” code of the predicate based on the “context module” that is maintained in the VM.

2 Likes

Thanks.

I was wondering why I was having such a hard time finding this.

This looks like the code based on the comment.

pl-vmi.c

Meta-predicate argument qualification. S_MQUAL qualifies the Nth
argument. S_LMQUAL does the same and resets the context module of the
frame to be definition module of the predicate, such that unqualified
calls refer again to the definition module. This sequence must be
processed as part of the supervisor, notably before creating the first
choicepoint.

1 Like