LinkValue

From OpenCog
Jump to: navigation, search

The LinkValue is a kind of value. It allows for the specification of a vector of other values. This allows values to be hierarchically arranged, in a tree, for example to hold structured JSON data or structured YAML data.

Note that Atoms are a special case of values, so you can place atoms into LinkValues. (As a general rule, be sure to put the atom into some atomspace first, and only then put it into a LinkValue.)

Example usage:

(LinkValue 
   (StringValue "foo") 
   (FloatValue 41 43 43 44)
   (Concept "foobar"))

creates a value. To associate it with an atom, say:

(cog-set-value! (Concept "abc") (Predicate "key")
  (LinkValue 
     (StringValue "foo") 
     (FloatValue 41 43 43 44)
     (Concept "foobar")))

The above sets the value on ConceptNode "abc", placing it at the key of PredicateNode "key". To fetch it, say

 (cog-value (Concept "abc") (Predicate "key"))

To get the actual list back, use either cog-value->list to get the whole list, or use cog-value-ref to get the n'th element. Example:

(cog-value->list (cog-value (Concept "abc") (Predicate "key")))

(cog-value-ref (cog-value (Concept "abc") (Predicate "key")) 2)