lojix/logic/src/main/com/thesett/aima/logic/fol/compiler/SymbolKeyTraverser.java
public Iterator<Operator<Term>> traverse(Functor functor, boolean reverse)
    {
        /*log.fine("Traversing functor " + functor.toString(interner, true, false));*/

        Queue<Operator<Term>> queue = (!reverse) ? new StackQueue<Operator<Term>>() : new LinkedList<Operator<Term>>();

        Term[] arguments = functor.getArguments();

        // For a top-level functor clear top-level flag, so that child functors are not taken as top-level.
        if (arguments != null)
        {
            for (int i = 0; i < arguments.length; i++)
            {
                Term argument = arguments[i];

                // When navigating onto a variable, the variable is scoped within a clause, and may appear many times
                // within it. Therefore it always uses its unique id relative to the root symbol table for the
                // clause as its contextual position. Other terms use their position path and are relative to the
                // the current positions symbol table.
                SymbolTable<Integer, String, Object> contextSymbolTable;

                if (argument.isVar())
                {
                    contextSymbolTable = clauseScopedSymbolTable.enterScope(CLAUSE_FREEVAR_INDEX);
                    /*log.fine("Enter freevar scope");*/

                    argument.setReversable(new ContextOperator(contextSymbolTable,
                            createTermOperator(argument, i, functor)));
                    argument.setTermTraverser(this);
                    queue.offer(argument);

                    /*log.fine("Created: " +
                        ("var argument operator on " + argument.toString(interner, true, false)));*/
                }
                else
                {
                    contextSymbolTable = null;

                    argument.setReversable(new ContextOperator(contextSymbolTable, i,
                            createTermOperator(argument, i, functor)));
                    argument.setTermTraverser(this);
                    queue.offer(argument);

                    /*log.fine("Created: " +
                        ("argument operator " + i + " on " + argument.toString(interner, true, false)));*/
                }

            }
        }

        return queue.iterator();
    }
public Iterator<Operator<Term>> traverse(Functor functor, boolean reverse)
    {
        /*log.fine("Traversing functor " + functor.toString(interner, true, false));*/

        Queue<Operator<Term>> queue = (!reverse) ? new StackQueue<Operator<Term>>() : new LinkedList<Operator<Term>>();

        Term[] arguments = functor.getArguments();

        // For a top-level functor clear top-level flag, so that child functors are not taken as top-level.
        if (arguments != null)
        {
            for (int i = 0; i < arguments.length; i++)
            {
                Term argument = arguments[i];

                // When navigating onto a variable, the variable is scoped within a clause, and may appear many times
                // within it. Therefore it always uses its unique id relative to the root symbol table for the
                // clause as its contextual position. Other terms use their position path and are relative to the
                // the current positions symbol table.
                SymbolTable<Integer, String, Object> contextSymbolTable;

                if (argument.isVar())
                {
                    contextSymbolTable = clauseScopedSymbolTable.enterScope(CLAUSE_FREEVAR_INDEX);
                    /*log.fine("Enter freevar scope");*/

                    argument.setReversable(new ContextOperator(contextSymbolTable,
                            createTermOperator(argument, i, functor)));
                    argument.setTermTraverser(this);
                    queue.offer(argument);

                    /*log.fine("Created: " +
                        ("var argument operator on " + argument.toString(interner, true, false)));*/
                }
                else
                {
                    contextSymbolTable = null;

                    argument.setReversable(new ContextOperator(contextSymbolTable, i,
                            createTermOperator(argument, i, functor)));
                    argument.setTermTraverser(this);
                    queue.offer(argument);

                    /*log.fine("Created: " +
                        ("argument operator " + i + " on " + argument.toString(interner, true, false)));*/
                }

            }
        }

        return queue.iterator();
    }
{@inheritDoc}