lojix/wam_prolog/src/main/com/thesett/aima/logic/fol/wam/compiler/BuiltInTransformVisitor.java
protected void leaveFunctor(Functor functor)
    {
        int pos = traverser.getPosition();

        if (!traverser.isInHead() && (pos >= 0))
        {
            Functor transformed = builtInTransform.apply(functor);

            if (functor != transformed)
            {
                /*log.fine("Transformed: " + functor + " to " + transformed.getClass());*/

                BuiltInFunctor builtInFunctor = (BuiltInFunctor) transformed;

                Term parentTerm = traverser.getParentContext().getTerm();

                if (parentTerm instanceof Clause)
                {
                    Clause parentClause = (Clause) parentTerm;

                    parentClause.getBody()[pos] = builtInFunctor;

                }
                else if (parentTerm instanceof Functor)
                {
                    Functor parentFunctor = (Functor) parentTerm;

                    parentFunctor.getArguments()[pos] = builtInFunctor;
                }
            }
        }
    }
protected void leaveFunctor(Functor functor)
    {
        int pos = traverser.getPosition();

        if (!traverser.isInHead() && (pos >= 0))
        {
            Functor transformed = builtInTransform.apply(functor);

            if (functor != transformed)
            {
                /*log.fine("Transformed: " + functor + " to " + transformed.getClass());*/

                BuiltInFunctor builtInFunctor = (BuiltInFunctor) transformed;

                Term parentTerm = traverser.getParentContext().getTerm();

                if (parentTerm instanceof Clause)
                {
                    Clause parentClause = (Clause) parentTerm;

                    parentClause.getBody()[pos] = builtInFunctor;

                }
                else if (parentTerm instanceof Functor)
                {
                    Functor parentFunctor = (Functor) parentTerm;

                    parentFunctor.getArguments()[pos] = builtInFunctor;
                }
            }
        }
    }
Applies the built-in transform during a post-fix visit of a term.

@param functor The functor to visit.