MapLink

From OpenCog
Jump to: navigation, search

The MapLink a link type analogous to the `map` function commonly found in functional programming languages, such as the scheme SRFI-1 `map`, or `map` in haskell.

MapLink generalizes of the map concept in several ways. First, the MapLink can be applied to either SetLinks or ListLinks. Secondly, MapLink performs type-checking on its inputs, so that mismatched inputs are discarded; thus, it is a kind of FilterLink.

In many ways, MapLink is similar to BindLink, except that MapLink does not search the entire atomspace for matching patterns; rather, it only examines the given input list/set, and applies the map to that.

In many ways, MapLink is the opposite of PutLink, in that it un-does a beta reduction, by extracting values from a matching pattern. Thus, MapLink could have been named UnPutLink, CoPutLink or ExtractLink or UnBetaReduceLink. See the page Atom relationships for more about opposites.

These ideas are illustrated in the examples shown in /examples/guile/map.scm. The first 4 examples illustrate the extraction of values for a single variable; this is, of un-beta-reducing a single composition. This includes a demonstration of type checking, which can be used to implement filtering. The next few examples show how multi-variable extraction works, as a straight-forward extension of the single-variable case. The final examples illustrate actual "mapping", that is, graph re-writing or graph transformation as a result of applying a mapping function.