110 likes | 491 Views
Prolog. Prolog is a logic programming language. It is a general purpose language often associated with artificial intelligence and computational linguistics . It has a purely logical subset, called "pure Prolog", as well as a number of extralogical features. Prolog. Data Types. Term.
E N D
Prolog Prolog is a logic programming language. It is a general purpose language often associated with artificial intelligence and computational linguistics. It has a purely logical subset, called "pure Prolog", as well as a number of extralogical features.
Prolog Data Types
Term • Prolog has only one data type called Term. Terms can be classified as follows. • Atom • Number • Variable • Compound Term
Atom • A general-purpose name with no inherent meaning. • This is normally composed of alphanumeric characters, together with ‘_’, beginning in the lower-case letter. • Any sequence of special characters such as + - * / < > = ` ~ : . / ? @ # $ & can also be used to form atoms, however, they should be enclosed in single quotes. • A sequence of any characters at all is accepted as an atom if the whole is delimited by single quotes.
Atom • Atoms beginning with a capital letter must also be quoted, to distinguish them from the variables. • The following are also, by convention, atoms: ! ; [] { } • Be careful with the use of square brackets because it can denote an atom (‘]’ or ‘[‘) or an empty list ([]).
Atom • Examples: • x • blue • ‘Taco’ • ‘some atom’ • [ ] --- empty list
Number • One example that follows implementation-dependent rules because it can be floats or integers but some implementations also provide unbounded integers and rational numbers. • Most also allow decimals and exponent notation. • Integers can be often expressed in bases from 2 to 9. i.e. 5’132 represents 42
Variable • Normally composed of alphanumeric characters plus ‘_’, beginning with an upper-case letter or ‘_’. • Closely resemble variables in logic in that they are placeholders for arbitrary terms. • A variable can become instantiated (bound to a specific term) via unification.
Variable • A single ‘_’ denotes an anonymous variable and means “any term”. • Unlike other variables, the underscore does not represent the same value everywhere it occurs. • Any other variable name has as its scope the clause in which it appears, or to be more precise the instance of the clause in which it appears, and within a clause each occurrence of a variable name stands for the same non-variable term.
Compound Term • Usually referred to by its principal functor. • Functor – distinguished by its two components: name and arity (alias number of arguments) • The arguments are also terms. • Atoms are functors of arity 0.
Compound Term • Written in the form: • functor_name(arg1, arg2, …, argN) • where the principal functor is referred to in writing as functor_name/N • take note that there is no space between the functor name and the opening bracket