public override bool Unify(BaseTerm t, VarStack varStack) { if (t is Variable) { return(t.Unify(this, varStack)); } NextUnifyCount(); const double eps = 1.0e-6; // arbitrary, cosmetic if (t is DecimalTerm) { return(Math.Abs(im) < eps && Math.Abs(re - ((DecimalTerm)t).ValueD) < eps); } if (t is ComplexTerm) { return(Math.Abs(re - ((ComplexTerm)t).Re) < eps && Math.Abs(im - ((ComplexTerm)t).Im) < eps); } //if (t is ComplexTerm) // return ( re == ((ComplexTerm)t).Re && im == ((ComplexTerm)t).Im ); return(false); }
public static bool SetWorkingDirectory(BaseTerm term, VarStack varStack) { if (term.Arity == 0) { workingDirectory = GetConfigSetting("WorkingDirectory", null); IO.Message("Working directory set to '{0}'", WorkingDirectory); return(true); } BaseTerm t0 = term.Arg(0); if (t0.IsVar) { t0.Unify(new StringTerm(workingDirectory), varStack); // symbolic names return(true); } string wd = Utils.DirectoryNameFromTerm(t0); if (wd == null) { IO.Error("Illegal name '{0}' for working directory", t0.FunctorToString); return(false); } workingDirectory = wd; IO.Message("Working directory set to '{0}'", WorkingDirectory); return(true); }
// try to bind the variable associated with the list of search alternatives // (t1|t2|...|tn) to the target term found matching one of these alternatives bool TryBindingAltListVarToMatch(BaseTerm AltListVar, BaseTerm searchTerm, VarStack varStack) { if (AltListVar == null) { return(true); } return(AltListVar.Unify(searchTerm, varStack)); }
private AltLoopStatus TryOneAlternative(int ip, VarStack varStack, ListPatternElem e, int k, int marker, ListTerm RangeList, int i, BaseTerm t, ref bool negSearchSucceeded, BaseTerm searchTerm) { bool unified = searchTerm.Unify(t, varStack); if (e.IsNegSearch) // none of the terms in the inner loop may match. ~(a | b | c) = ~a & ~b & ~c { if (unified) // ... no point in investigating the other alternatives if one does { negSearchSucceeded = false; return(AltLoopStatus.Break); // don't try the other alternatives } return(AltLoopStatus.TryNextDown); // non of the downranges matches may lead to a success } else { if (unified && // we found a match. Unify, and TryBindingAltListVarToMatch(e.AltListBindVar, t, varStack) && // bind the AltListBindVar to the match TryBindingRangeRelatedVars(e, i, RangeList, varStack)) // bind the range to the range variables { if (ip == pattern.Length - 1) // this was the last pattern element { if (k == target.Count - 1) // both pattern and target exhausted { return(AltLoopStatus.MatchFound); } } else if (UnifyTailEx(ip + 1, k + 1, varStack)) // now deal with the rest { return(AltLoopStatus.MatchFound); } } // if we arrive here, it was not possible to ... // (1) ... unify the range's SearchTerm with the target element, or // (2) ... unify the range variable with the range list, or // (3) ... successfully process the rest of the pattern and target // Now unbind and try matching with the next target element BaseTerm.UnbindToMarker(varStack, marker); return(AltLoopStatus.TryNextDown); // try the next downrange match } }
// try to bind the variable associated with the last of search alternatives // (t1|t2|...|tn) to the target term found matching one of these alternatives bool TryBindingAltListVarToMatch (BaseTerm AltListVar, BaseTerm searchTerm, VarStack varStack) { if (AltListVar == null) return true; return AltListVar.Unify (searchTerm, varStack); }
private AltLoopStatus TryOneAlternative (int ip, VarStack varStack, ListPatternElem e, int k, int marker, ListTerm RangeList, int i, BaseTerm t, ref bool negSearchSucceeded, BaseTerm searchTerm) { bool unified = searchTerm.Unify (t, varStack); if (e.IsNegSearch) // none of the terms in the inner loop may match. ~(a | b | c) = ~a & ~b & ~c { if (unified) // ... no point in investigating the other alternatives if one does { negSearchSucceeded = false; return AltLoopStatus.Break; // don't try the other alternatives } return AltLoopStatus.TryNextDown; // non of the downranges matches may lead to a success } else { if (unified && // we found a match. Unify, and TryBindingAltListVarToMatch (e.AltListBindVar, t, varStack) && // bind the AltListBindVar to the match TryBindingRangeRelatedVars (e, i, RangeList, varStack)) // bind the range to the range variables { if (ip == pattern.Length - 1) // this was the last pattern element { if (k == target.Count - 1) // both pattern and target exhausted return AltLoopStatus.MatchFound; } else if (UnifyTailEx (ip + 1, k + 1, varStack)) // now deal with the rest return AltLoopStatus.MatchFound; } // if we arrive here, it was not possible to ... // (1) ... unify the range's SearchTerm with the target element, or // (2) ... unify the range variable with the range last, or // (3) ... successfully process the rest of the pattern and target // Now unbind and try matching with the next target element BaseTerm.UnbindToMarker (varStack, marker); return AltLoopStatus.TryNextDown; // try the next downrange match } }