What do they mean in the prologue?

Firstly, when I read various predicates in Prolog, for example, http_server , he wrote like this: http_server(:Goal, +Options) which means : and + here? Sometimes also recorded ? .
Secondly, sometimes I see variables declared with an underscore in front of them, like _Request , although there is no other Request , why?

+5
source share
1 answer

Symbols + , - ,: etc. called mode declarations. They describe the expected instance of the predicate arguments, that is, whether you should expect to call the predicate with an unbound variable, instance-instance, etc. They are not fully standardized; here is a description of the conventions for SWI-Prolog: http://www.swi-prolog.org/pldoc/man?section=modes

As a first approximation, the argument + is the input to the predicate, you must provide the basic term. An argument is the result of a predicate, the predicate will try to combine it with the term. Term ? can be partially instantiated upon invocation, and the predicate can repeat it. Argument : is a meta argument, i.e. Its target should be called by a predicate (for example, in setof/3 ).

In the http_server(:Goal, +Options) example http_server(:Goal, +Options) you should call this predicate the first argument associated with the target, probably the name of the predicate. The second argument should be created, presumably, in a list whose format is further described in the documentation. If you do not call this predicate, for example, if you pass an unbound variable as the second argument, you may get unexpected behavior or an instance creation error.

As for your second question (which would be better separate), a variable starting with an underscore is called an anonymous variable. Each such variable can occur only once for each sentence, except for _ itself, which can occur several times and refers to separate variables in each case.

Prolog systems usually generate a “singleton variable” warning for non-anonymous variables that occur only once, because it may be typos or a sign that the programmer has forgotten something. You use anonymous variables to express the opinion that “there must be something (such as a predicate argument), but I don’t care what it is.” In your example, you are supposedly calling a predicate with the query argument, but in your particular use case, you do not need the query.

+7
source

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


All Articles