/*
 * @(#)$Id: eval_def,v 1.1 1996/12/11 15:09:20 img Exp $
 *
 * $Log: eval_def,v $
 * Revision 1.1  1996/12/11 15:09:20  img
 * Merge of mthd and smthd libraries.
 *
 * Revision 1.4  1996/05/23 11:20:36  img
 * incorrect argument order in reduction_rule/6
 *
 * Revision 1.3  1996/05/14  16:00:09  img
 * Use reduction rules
 *
 * Revision 1.2  1995/12/04  14:11:57  img
 * evaluation order documented;  don't eval_def functor positions
 *
 * Revision 1.1  1994/09/16  09:34:27  dream
 * Initial revision
 */

/* Symbolically evaluates a term in the goal by applying one of its
 * defining equations.  In order to prevent interference with rippling
 * it will not apply when waves are present.
 * 
 * Evaluation is in a outermost/rightmost reduction strategy.  This
 * ordering is as result of exp-at/3 term traversal.  */
method(eval_def( Pos, [Rule,Dir]),
       H==>G,
       [matrix(Vars,Matrix,G),
        wave_fronts(_, [], Matrix),
        exp_at(Matrix,Pos,Exp),
	\+ Pos = [0|_],				%don't eval functors
        not metavar(Exp),			%or meta-variables
	reduction_rule(Exp,NewExp,C,Dir,Rule,_),
        polarity_compatible(Matrix, Pos, Dir),
        elementary(H==>C,_)
       ],
       [% Once have applied a base-case ignore wave-fronts
        replace(Pos,NewExp,Matrix,NewMatrix),
        matrix(Vars,NewMatrix,NewG)
       ],
       [H==>NewG],
       eval_def(Pos,[Rule,Dir])
      ).


