ValueOfLink

From OpenCog
Jump to: navigation, search

The ValueOfLink is a Link that returns the Value associated to some atom at some key. It must have the format:

ValueOfLink
   SomeAtom
   PredicateNode "some key"

On execution, it returns the Value at the indicated location. On evaluation, it fetches the Value, and, if that value is itself evaluatable, then it is evaluated.

The ValueOfLink is primarily used in PredicateFormulaLinks, which allow truth-value formulas to be specified in Atomese.

Closely related is the StreamValueOfLink, which can be used to sample values out of a stream.

Examples

Set a value, then fetch it:

(use-modules (opencog) (opencog exec))

(cog-set-value! (Concept "A") (Predicate "key") (FloatValue 42))
(cog-execute! (ValueOf (Concept "A") (Predicate "key")))

Perform numeric arithmetic on values:

(cog-set-value! (Concept "A") (Predicate "key")
    (FloatValue 1 2 3 42))
(cog-execute! (PlusLink (NumberNode 3)
    (ValueOf (Concept "A") (Predicate "key"))))

Perform numeric comparisons:

(cog-set-value! (Concept "A") (Predicate "key")
    (RandomStream 1))
(cog-evaluate! (GreaterThanLink (Number 0.5)
    (ValueOf (Concept "A") (Predicate "key"))))

Chain together sequences of values:

(cog-set-value! (Concept "Bee") (Predicate "other key")
    (GreaterThan (Number 0.5)
       (ValueOf (Concept "A") (Predicate "key"))))
(cog-evaluate! (ValueOf (Concept "Bee") (Predicate "other key")))

Additional tutorials and examples can be found in the /examples directory.

See also