From OpenCog
(Redirected from Executable)
Jump to: navigation, search

All Atoms can be used to represent symbolic knowledge as a graph: this is what the AtomSpace is -- an in-RAM database for (hyper-)graphs encoding knowledge. However, many atoms can also be executed, thus performing the actual computations that they encode as graphs.

The most direct example of this would be the graph

(Plus (Number 2) (Number 3))

This is a graph -- a tree -- that symbolically encodes the concept of "adding together 2 and 3". As such, this graph can be saved to disk, for later retrieval; one can apply symbolic reasoning or inference; one can perform reduction, or any number of other graphical manipulations to this expression.

It can also be directly executed, to produce the number 5.

Graphs which encode knowledge, but which also can be executed are referred to as Atomese. They can be visualized as "pipes" through which values "flow", like water through water pipes. The symbolic representation, as graphs, allows "plumbers" - such as reasoning, inferencing or reduction systems to analyze and alter the shapes and connections of the pipes (of the graphs). These plumbers represent knowledge by arranging the pipes in certain ways. Once some particular executable graph has been constructed, it can then be put to work, actually preforming the computation that it abstractly, symbolically represents.

Thus, many Atoms play a dual role: they are used to represent knowledge, and also to perform computation. A large class of executable atoms are the FunctionLinks, which include the arithmetic link types, as well as many others. Examples include the ValueOf Link, which can be used to introduce values into the processing pipeline. Another is the ExecutionOutputLink, which can be used to interface to external (non-Atomese) systems.


The cog-execute! function is a scheme function that is able to execute all executable links types. It is part of (opencog exec) module. This page reviews what cog-execute! does today. This may change over time.

When cog-execute! is called on an atom, it forces execution to take place immediately. The result (output) of execution may be an Atom or a Value. If the result is an Atom, then it is immediately placed in the current AtomSpace. (This is subject to change in the future, as the semantics and use-cases of multiple AtomSpaces become more clear).

Non-executable Atoms are left alone, when executed: they are treated as constants. Thus, for example:

(cog-execute! (ConceptNode "asdf"))

results in:

(ConceptNode "asdf")

Example: PlusLink

The PlusLink is an excellent, easy example of a FunctionLink that cog-execute! knows how to handle. Thus

      (NumberNode "2")
      (NumberNode "3")))


(NumberNode "5")

The word "returns" here has two meanings: the scheme function cog-execute! literally returns (NumberNode "5") as it's return value, and also, as a side effect, the atom (NumberNode "5") is placed into the atomspace. These are two different concepts of "return" that are easy to confuse and conflate with each-other. Be careful.

List of executable atom types

See Category:Executable Atom Types for a full list.

See also