I have this code:
set_value(X,Value,[X/_|T],[X/Value|T]).
set_value(X,Value,[Y/V|T],[Y/V|NewT):- X\=Y,set_value(X,Value,T,NewT).
set_value(X,Value,[],[X/Value]).
But I cannot figure out what does / do. It looks like it pairs variables, but I'm not 100% sure. It definitely isn't division operator. Thanks.
As EMS and Chac explained this number denotes number of arguments. The reason why you will find this number in documentation is because predicates with same name and different arity (number of arguments) are different predicates.
A single underscore ( _ ) denotes an anonymous variable and means "any term". Unlike other variables, the underscore does not represent the same value everywhere it occurs within a predicate definition. A compound term is composed of an atom called a "functor" and a number of "arguments", which are again terms.
An operator is an operatorIn Prolog, we can use the predicate current_op/3 to learn more about operators. For example: ?- current_op(Prec, Type, =:=).
Introduction : Prolog is a logic programming language. It has important role in artificial intelligence. Unlike many other programming languages, Prolog is intended primarily as a declarative programming language. In prolog, logic is expressed as relations (called as Facts and Rules). Core heart of prolog lies at the logic being applied.
/ (slash) Syntax. /(slash) Executes the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer. The buffer has no command history and does not record SQL*Plus commands. Usage. You can enter a slash (/) at the command prompt or at a line number prompt of a multi-line command.
Slashes can also be used to form some abbreviations or shortened forms of words or phrases, although these shouldn’t be used in formal writing. Notice that in these cases, no space is necessary after the slash.
In prolog, logic is expressed as relations (called as Facts and Rules). Core heart of prolog lies at the logic being applied. Formulation or Computation is carried out by running a query over these relations. Open a terminal (Ctrl+Alt+T) and type: Syntax and Basic Fields : In prolog, We declare some facts.
It doesn't do anything; it's used here to construct pairs, as you already figured.
Since the /
doesn't occur on the right-hand side of is
or in another place where arithmetic evaluation is performed, Prolog just produces two-argument terms with /
as the functor. /
is used because it can be written infix; -
is also a popular choice for a generic pair constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With