Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does slash(/) do in prolog?

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.

like image 782
peto1234 Avatar asked Apr 11 '12 18:04

peto1234


People also ask

What is Slash in Prolog?

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.

What is the underscore in Prolog?

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.

Is Prolog an operator?

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, =:=).

What is Prolog?

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.

What does the slash mean in SQL?

/ (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.

What are slashes used for in writing?

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.

How do you Write Logic in Prolog?

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.


1 Answers

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.

like image 94
Fred Foo Avatar answered Sep 27 '22 17:09

Fred Foo