
com.thesett.aima.logic.fol.prolog.builtins.DefaultBuiltIn Maven / Gradle / Ivy
/*
* Copyright The Sett Ltd, 2005 to 2014.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.thesett.aima.logic.fol.prolog.builtins;
import java.util.LinkedList;
import java.util.List;
import com.thesett.aima.logic.fol.Functor;
import com.thesett.aima.logic.fol.Variable;
/**
* The DefaultBuiltIn implements an implicit default built-in operator that implements the normal processing pathway in
* a Prolog program. That is, the head of the goal stack is unified against the head of the current clause chosen for
* examination at this step of the proof, and if a match is found, the functors in the clause body are pushed onto the
* goal stack (in reverse order, so that they are processed intuitively left-to-right when popped off again).
*
*
CRC Card
* Responsibilities Collaborations
* Unify the current goal against the head of the current clause.
* {@link ResolutionState}, {@link PrologUnifier}
* Create any new goals resulting from the RHS of the unified against clause.
* {@link ResolutionState}.
*
*
* @author Rupert Smith
*/
public class DefaultBuiltIn extends BaseBuiltIn
{
/** Used for providing user readable execution traces. */
/* private static final Logger trace = Logger.getLogger("TRACE.Prolog." + DefaultBuiltIn.class.getSimpleName()); */
/** Flag used as a quick check to see if trace is enabled. */
private static final boolean TRACE = false; //log.isLoggable(Level.FINE)
/**
* Creates a default built-in to implement the specified functor.
*
* @param functor The functor to implement as a built in.
*/
public DefaultBuiltIn(Functor functor)
{
super(functor);
}
/** {@inheritDoc} */
public boolean proofStep(ResolutionState state)
{
Functor goalTerm = state.getGoalStack().peek().getFunctor();
Functor matchTerm = state.getCurrentClause().getHead();
// This is used to record variables bound on the domain side of the unificiation. This information seems
// like is does not need to be kept because usually all of these bindings are in the stack frame.
// However, this is not always the case as unification can capture a variable on the domain side.
// These variables need to be unbound on backtracking too.
List© 2015 - 2025 Weber Informatics LLC | Privacy Policy