Statements --- These are some simple statements. x=1 y=2 and x=1 y=2 or x=1 Logic programming --- Styles and Paradigms --- We'd like to make a distinction between style and paradigms. x = double(2) //functional double(2,x) //logic The first line is written in a functional style. It can be read as "x _is_ the double of 2". The second is written in logic-style. "The double of x is 2". Either way, they are equivalent. As far as the language is concerned, it's simple syntax sugar. One is shorthand for the other. As a multi-paradigm (or logic-functional with objects) language, we bend the distinction between what are considered the "main programming paradigms". Logic-procedural --- and/or --- They control the flow of statements. > x=1 and y=2 | x=1 and y=2 _and_ statements are evaluated sequentially. In a procedural language, it's akin to a semicolon. (In a sense, this is the normal form of evaluation we see in any language, whereas...) > x=1 or x=2 | x=1 | x=2 A simple _or_ statement splits evaluation. Logically, the statement is satisfied if either is true. Hence, our query has two results. Relations --- Whereas most languages have functions, Cosmos has relations. This is how we encode our previous statements in the form of a relation, ``` rel p(x) x=1 or x=2 ``` We can then state that, ``` p(x) ``` Or, even, ``` x=p() ``` What this entails is that x can be either 1 or 2. We do not know which. Compare it to the following code. ``` rel p(x) x=1 or x=2 p(x) x!=1 io.writeln(x) //2 ``` Logically, we're saying that x can be either 1 or 2. This is implied by p(x). We then say x _is not_ 1. It follows that it is 2. Thus, when we write the value of x in the last line-- we can be sure that 2 is written. Procedurally, it's a bit more complicated. Analogy by quantum cat --- At the moment our logic engine sees p(x), x has two possible values. If you've ever heard the parable of the quantum cat--a cat that is both dead and alive, you may think of it in those terms. x is in a _superposition_ of two values-- furthermore, the value of x-- and consequentially the result of p(x)-- is nondeterministic. There is no determined answer for the query "what is x right now?". Next, our engine sees x!=1. Once we know that x is not 1, it can only be 2. Backtracking --- # Host language Pack --- **cstart/0.** Opens the interpreter. **ceval/1.** Evaluates code then closes the session. e.g. :- ceval('x=1 or y=3'). **ui/0.** Graphical swi debugger. Shorthand for guitracer,trace. **cmodule/1.** Compiles module e.g. :- cmodule('name') ; name.co is a language file