lojix/wam_prolog/src/main/com/thesett/aima/logic/fol/wam/compiler/PositionAndOccurrenceVisitor.java
protected void enterFunctor(Functor functor)
    {
        /*log.fine("Functor: " + functor.getName() + " <- " + symbolTable.getSymbolKey(functor.getName()));*/

        // Only check position of occurrence for constants.
        if (functor.getArity() == 0)
        {
            // Add the constant to the set of all constants encountered.
            List<SymbolKey> constantSymKeys = constants.get(functor.getName());

            if (constantSymKeys == null)
            {
                constantSymKeys = new LinkedList<SymbolKey>();
                constants.put(functor.getName(), constantSymKeys);
            }

            constantSymKeys.add(functor.getSymbolKey());

            // If the constant ever appears in argument position, take note of this.
            if (inTopLevelFunctor(traverser))
            {
                argumentConstants.add(functor.getName());
            }
        }

        // Keep track of the current top-level body functor.
        if (isTopLevel(traverser) && !traverser.isInHead())
        {
            topLevelBodyFunctor = functor;
        }
    }
protected void enterFunctor(Functor functor)
    {
        /*log.fine("Functor: " + functor.getName() + " <- " + symbolTable.getSymbolKey(functor.getName()));*/

        // Only check position of occurrence for constants.
        if (functor.getArity() == 0)
        {
            // Add the constant to the set of all constants encountered.
            List<SymbolKey> constantSymKeys = constants.get(functor.getName());

            if (constantSymKeys == null)
            {
                constantSymKeys = new LinkedList<SymbolKey>();
                constants.put(functor.getName(), constantSymKeys);
            }

            constantSymKeys.add(functor.getSymbolKey());

            // If the constant ever appears in argument position, take note of this.
            if (inTopLevelFunctor(traverser))
            {
                argumentConstants.add(functor.getName());
            }
        }

        // Keep track of the current top-level body functor.
        if (isTopLevel(traverser) && !traverser.isInHead())
        {
            topLevelBodyFunctor = functor;
        }
    }
{@inheritDoc}

<p/>Checks if a constant ever appears in an argument position.

<p/>Sets the 'inTopLevelFunctor' flag, whenever the traversal is directly within a top-level functors arguments.
This is set at the end, so that subsequent calls to this will pick up the state of this flag at the point
immediately below a top-level functor.