-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added MutableVariableSubstitution. Derives from VariableSubstitution and is modifiable in-place. Added `ToMutable` method to VariableSubstitution * Added `CopyAndAdd` methods to VariableSubstitution. * Breaking: renamed `VariableSubstitution.Clone()` to `VariableSubstitution.Copy()`. Didn't want to use the term "Clone" for the methods above, because "Clone" suggests no change more strongly than "Copy" does - "CloneAndAdd" is a bit awkward. So renaming this method for consistency. (..and not implementing ICloneable anyway..)
- Loading branch information
Showing
5 changed files
with
111 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/SCFirstOrderLogic/SentenceManipulation/MutableVariableSubstitution.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SCFirstOrderLogic.SentenceManipulation; | ||
|
||
/// <summary> | ||
/// A <see cref="VariableSubstitution"/> that can be modified in-place. | ||
/// </summary> | ||
public class MutableVariableSubstitution : VariableSubstitution | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MutableVariableSubstitution"/> class that is empty. | ||
/// </summary> | ||
public MutableVariableSubstitution() | ||
: base() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MutableVariableSubstitution"/> class that uses a given set of bindings. | ||
/// </summary> | ||
/// <param name="bindings">The bindings to use.</param> | ||
public MutableVariableSubstitution(IEnumerable<KeyValuePair<VariableReference, Term>> bindings) | ||
: base(bindings) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Adds a binding. | ||
/// </summary> | ||
/// <param name="variable">A reference to the variable to be substituted out.</param> | ||
/// <param name="term">The term to be substituted in.</param> | ||
public void AddBinding(VariableReference variable, Term term) | ||
{ | ||
bindings.Add(variable, term); | ||
} | ||
|
||
/// <summary> | ||
/// Creates an immutable copy of this substitution. | ||
/// </summary> | ||
/// <returns>A new <see cref="VariableSubstitution"/> instance with the same bindings as this one.</returns> | ||
public VariableSubstitution ToReadOnly() | ||
{ | ||
return new VariableSubstitution(bindings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters