Warren Abstract Machine - Example

Example

Here is a piece of Prolog code:

girl(sally). girl(jane). boy(B) :- \+ girl(B).

A WAM-based Prolog compiler will compile this into WAM instructions similar to the following:

predicate(girl/1): switch_on_term(2,1,fail,fail,fail), label(1): switch_on_atom label(2): try_me_else(4) label(3): get_atom(sally,0) proceed label(4): trust_me_else_fail label(5): get_atom(jane,0) proceed predicate(boy/1): get_variable(x(1),0) put_structure(girl/1,0) unify_local_value(x(1)) execute((\+)/1)])

An important characteristic of this code is its ability to cope with the various modes in which the predicates can be evoked: Any argument might be a variable, a ground term, or a partly instantiated term. The "switch" instructions handle the different cases.

Read more about this topic:  Warren Abstract Machine

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)