Class SimpleConstSubstitution
java.lang.Object
edu.harvard.seas.pl.abcdatalog.util.substitution.SimpleConstSubstitution
- All Implemented Interfaces:
ConstOnlySubstitution,Substitution
A mapping from variables to constants.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty substitution.Constructs a copy of another substitution. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAttempts to add a mapping to the substitution.Term[]Apply this substitution to a list of terms, creating a new list.Returns the constant a variable is mapped to in this substitution.voidAdds a mapping from a variable to a constant to this substitution.toString()static SimpleConstSubstitutionCreates a substitution from unifying two lists of terms, the second of which must be ground (i.e., contain no variables).
-
Constructor Details
-
SimpleConstSubstitution
public SimpleConstSubstitution()Constructs an empty substitution. -
SimpleConstSubstitution
Constructs a copy of another substitution.- Parameters:
other- the other substitution
-
-
Method Details
-
get
Returns the constant a variable is mapped to in this substitution.- Specified by:
getin interfaceConstOnlySubstitution- Specified by:
getin interfaceSubstitution- Parameters:
v- the variable- Returns:
- the constant, or null if v is not mapped
-
put
Adds a mapping from a variable to a constant to this substitution.- Parameters:
v- the variablec- the constant- Throws:
IllegalArgumentException- if v is already mapped to another constant
-
unify
Creates a substitution from unifying two lists of terms, the second of which must be ground (i.e., contain no variables).- Parameters:
xs- the first listys- the second list, which must be ground- Returns:
- the substitution, or null if the unification is not possible
- Throws:
IllegalArgumentException- if the second list of terms is not ground
-
apply
Description copied from interface:SubstitutionApply this substitution to a list of terms, creating a new list.- Specified by:
applyin interfaceSubstitution- Parameters:
terms- the original list- Returns:
- the new list
-
toString
-
add
Description copied from interface:ConstOnlySubstitutionAttempts to add a mapping to the substitution. Returns true if the mapping was made successfully (i.e., if the variable was not already mapped to another constant).- Specified by:
addin interfaceConstOnlySubstitution- Parameters:
x- the variablec- the constant- Returns:
- whether the mapping was successfully added
-