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
ConstructorDescriptionConstructs an empty substitution.Constructs a copy of another substitution. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Attempts 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.void
Adds a mapping from a variable to a constant to this substitution.toString()
static SimpleConstSubstitution
Creates 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:
get
in interfaceConstOnlySubstitution
- Specified by:
get
in 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:Substitution
Apply this substitution to a list of terms, creating a new list.- Specified by:
apply
in interfaceSubstitution
- Parameters:
terms
- the original list- Returns:
- the new list
-
toString
-
add
Description copied from interface:ConstOnlySubstitution
Attempts 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:
add
in interfaceConstOnlySubstitution
- Parameters:
x
- the variablec
- the constant- Returns:
- whether the mapping was successfully added
-