GetLink is used to specify a search pattern that can be satisfied with Atoms found in the AtomSpace. it is similar to BindLink, except that it does not perform any graph re-writing. it is similar to SatisfactionLink, except that, upon execution, it returns a set of atoms, instead of a truth value. It is similar to the SatisfyingSetLink, except that it is imperative: the GetLink commands: "go and search for all atoms that satisfy this predicate", whereas SatisfyingSetLink is declarative: "here is a set of atoms that satisfy this predicate".
The GetLink has the general form:
GetLink <optional variable declarations and type restrictions> <clause containing variables>
Alternatively GetLink can take a LambdaLink to express the variable declarions and the pattern
GetLink LambdaLink <optional variable declarations and type restrictions> <clause containing variables>
SetLink <atoms that ground the variables>
When there is only one grounding, the SetLink is omitted, and the single grounding is returned. When there are multiple variables in the pattern, these are enclosed in a ListLink; if there is only one variable, the ListLink is omitted.
The GetLink is essentially identical to the SatisfyingSetLink, except that the SatisfyingSetLink is declarative, whereas the GetLink is imperative. That is, the GetLink is used to force a search, right now, of all of the things in the AtomSpace that satisfy it's conditions. By contrast, the SatisfyingSetLink is declarative, and can be used during (PLN) reasoning and/or Markov (Viterbi) parsing: viz: if something satisfies this, then I can conclude this other thing.
(GetLink (VariableList (TypedVariableLink (VariableNode "$A") (TypeNode "ConceptNode")) (VariableNode "$B")) (InheritanceLink (VariableNode "$A") (VariableNode "$B")))
By default, GetLink finds all free variables in an expression, and binds them. Thus, if you wish to specify type restrictions for one variable, then you must provide a variable binding for all of the relevant variables; else they will become unbound.
Equivalence to BindLink
GetLink, as descried above, is completely equivalent to
BindLink <clause containing free variables> ListLink <the variables>
Observe also that BindLink is almost equivalent to a GetLink and a PutLink combined. That is, the form
BindLink <clauses containing variables> <re-write clauses>
is the almost exactly same thing as
PutLink <re-write clauses> GetLink <clauses containing variables>
A concrete example should help to illustrate this. Consider the following BindLink:
BindLink WhizzyLink SomeAtom "widget" VariableNode "$x" FooBarLink SomeAtom "thing-a-ma-bob" VariableNode "$x"
When the above is executed, it will find all possible groundings for the VariableNode $x, and it would then produce a SetLink containing a FooBarLink for each grounding. Exactly the same effect can be achieved by executing the following:
PutLink FooBarLink SomeAtom "thing-a-ma-bob" VariableNode "$x" GetLink WhizzyLink SomeAtom "widget" VariableNode "$x"
When the GetLink above is run, it will return a SetLink containing all possible groundings for the variable. The PutLink then takes this as an argument, substitutes those groundings for the variable in FooBarLink, and creates a bunch of FooBarLinks with the grounded values in them.
The above carefully states "almost exactly". So when do they differ? They differ whenever the GetLink might return several different values, which, inserted into the Put, results in the same final value. In this case, the Get-Put combination would return multiple identical results, while the BindLink would return one unique result. Consider, for example
PutLink FooBarLink SomeAtom "thing-a-ma-bob" VariableNode "$x" GetLink WhizzyLink SomeAtom "widget" VariableNode "$x" VariableNode "$y"
If the variable $x can be grounded one way, and the variable $y five ways, then the result of executing the PutLink will result in five identical copies of FooBarLink. By contrast
BindLink WhizzyLink SomeAtom "widget" VariableNode "$x" VariableNode "$y" FooBarLink SomeAtom "thing-a-ma-bob" VariableNode "$x"
will result in only one (unique) instance of FooBarLink. And so, except for this difference in multiplicity, BindLink and Get-Put both produce the same results.