InsertLink

From OpenCog
Jump to: navigation, search

Deprecated -- you should probably use PutLink instead. PutLink is more flexible and is .. prettier.

The InsertLink allows a Link to be described, in such a way that the description is in the AtomSpace, but the Link itself need not be. The link it describes is not inserted until the InsertLink is executed with the cog-execute! function, or with the pattern matcher.

The InsertLink is paired with the RemoveLink, which describes a link to be removed when it is executed. These two are roughly analogous to the Prolog concept of "assert" and "retract". The AssignLink combines the two into one, behaving like the assignment operator (viz the = sign in C++, python, perl) in procedural programming languages.

InsertLink, RemoveLink and AssignLink have the form of a special case of a SignatureLink.

Example

Consider the link

  (EvaluationLink)
     (PredicateNode "some property")
     (ListLink
        (ConceptNode "thing A")
        (ConceptNode "B-dom-ness")))

It's description is

  (SignatureLink
     (TypeNode "EvaluationLink")
     (PredicateNode "some property")
     (ListLink
        (ConceptNode "thing A")
        (ConceptNode "B-dom-ness")))

Because the signature differs from the link itself, the signature can be placed into the AtomSpace without creating the link itself. This allows the link to be created at a later time, or, if it already exists, to be removed. Thus, one may declare:

  (InsertLink
     (TypeNode "EvaluationLink")
     (PredicateNode "some property")
     (ListLink
        (ConceptNode "thing A")
        (ConceptNode "B-dom-ness")))

and also:

  (RemoveLink
     (TypeNode "EvaluationLink")
     (PredicateNode "some property")
     (ListLink
        (ConceptNode "thing A")
        (ConceptNode "B-dom-ness")))

These links can be executed with the cog-execute! function. They are also executed when they are in the target of a BindLink. As such, they are useful for implementing state and state machines in the AtomSpace: the potential state is described through signatures, while the actual state is manipulated when these links are executed.

The AssignLink combines the insert and remove into one, and thus behaves like the assignment operator in procedural programming languages.

The DeleteLink provides a different format for specifying links to be removed from the AtomSpace.

Implicit bound variables

Observe that

  (SignatureLink
     (TypeNode "EvaluationLink")
     (PredicateNode "some property")
     (ListLink
        (ConceptNode "thing A")
        (ConceptNode "B-dom-ness")))

is equivalent to a link with an explicitly bound variable:

  (TypedVariableLink
     (VariableNode "$x")
     (SignatureLink
        (TypeNode "EvaluationLink")
        (PredicateNode "some property")
        (ListLink
           (ConceptNode "thing A")
           (ConceptNode "B-dom-ness"))))

That is, the SignatureLink describes a variable that must have exactly the indicated signature. Thus, for example, during pattern matching, the variable $x could be grounded by any expression having that particular signature. Since the signature is very specific and narrow, the variable can be grounded by only one possible atom:

 (EvaluationLink
     (PredicateNode "some property")
     (ListLink
        (ConceptNode "thing A")
        (ConceptNode "B-dom-ness")))

This atom either will already exist in the AtomSpace, or it will not. Thus, we conclude that InsertLink is equivalent to the more complex description:

  (BindLink
     (TypedVariableLink
        (VariableNode "$x")
        (SignatureLink
           (TypeNode "EvaluationLink")
           (PredicateNode "some property")
           (ListLink
              (ConceptNode "thing A")
              (ConceptNode "B-dom-ness"))))
      (AbsentLink
           (VariableNode "$x"))
      (VariableNode "$x"))

The above BindLink, when executed, will have the effect of creating the EvaluationLink, if it does not exist, and having no effect if it does already exist.

See also