Did you know ... Search Documentation:
Pack cosmos -- docs/guide4.txt

3C. Paradigms

Logic

x=double(1)
y=x
print(y)

In the logic paradigm, or logic programming (LP), which we follow to the letter, as our language is in fact a logic programming language, this is simply a set of statements.

  • The double of 1 is x.
  • The variable of y equals x.
  • The value of y is written on the screen. It's easy to see by looking at the program that this applies. We may simply look at the program and see that x equals the result of a function double, y is x, and the value is written (which we know the statement print does).

    We only have to take a moment to conclude that 2 will be written if we run the program, and it is.

    2

Procedural

If a paradigm is a way to look at a given program, the procedural paradigm looks at it imperatively. A program is a recipe, or list of instructions to be executed by the computer.

This paradigm follows the computer program closely. It's the closest to how the computer actually acts.

The following instructions would be executed.

  1. A procedure or command double computes the double of 1.
  2. This value is given to x. A variable in the procedural paradigm is like a slot. In fact, it's a slot of computer memory and occupies a space in the computer.
  3. The value in x is then assigned to the slot y.
  4. The command to write the statement on the screen, print, is given. The difference so far is subtle, and you could take it as a procedural program as-is. In fact, our language highly resembles procedural languages in syntax.

    This is on purpose, the language is made so that it can be reasoned or written in this style to some extent.

Logic-Procedural

Though you may often simply see the program as a series of statements in the logic paradigm, it's sometimes needed to know how the computer executes them.

After all, the program runs in a computer.

We'll call this the "Logic-Procedural" paradigm (though it's a made-up term we invented). The Logic-Procedural interpretation of a program is given by how our procedural logic engine executes the logic program.

Often, the only reason we need to know this is so our program has good performance. An efficient program will run as quickly as it can and not consume many memory slots.

Limitations

3B. Pure Logic Programming

Most important for our language is the notion of a pure logic program.

Logic programs allow us to effectively write logical statements and have the language work them out correctly.

Writing pure relations

  • Any relation made of pure relations and operators is pure.
  • =, and, or, not, if and regular arithmetic are pure. Knowing you have written a pure relation is quite simple.

    All you have to do is use pure relations! Then, your relation is also pure.