Exemplo n.º 1
0
			public override bool Evaluate(Resource[] args, ref Resource @object) {
				if (args.Length != 2) return false;
				if (args[0] == null || !(args[0] is Literal)) return false;
				if (args[1] == null || !(args[1] is Literal)) return false;

				try {
				
				Decimal left = (Decimal)Convert.ChangeType( ((Literal)args[0]).ParseValue() , typeof(Decimal) );
				Decimal right = (Decimal)Convert.ChangeType( ((Literal)args[1]).ParseValue() , typeof(Decimal) );
				Resource newvalue = Literal.FromValue(Evaluate(left, right));
				if (@object == null) {
					@object = newvalue;
					return true;
				} else {
					return @object.Equals(newvalue);
				}

				} catch (FormatException) {
					return false;
				}
			}
Exemplo n.º 2
0
			public override bool Evaluate(Resource[] args, ref Resource @object) {
				Decimal sum = InitialValue;
				foreach (Resource r in args) {
					if (r == null) return false;
					if (!(r is Literal)) return false;
					try {
						Decimal v = (Decimal)Convert.ChangeType( ((Literal)r).ParseValue() , typeof(Decimal) );
						sum = Combine(sum, v);
					} catch (FormatException) {
						return false;
					}
				}
				Resource newvalue = Literal.FromValue(sum);
				if (@object == null) {
					@object = newvalue;
					return true;
				} else {
					return @object.Equals(newvalue);
				}
			}
Exemplo n.º 3
0
 private static bool unify(Resource s, Hashtable senv, Resource d, Hashtable denv, bool f)
 {
     if (s is Variable) {
         Resource sval = evaluate(s, senv);
         if (sval != null) return unify(sval, senv, d, denv, f);
         else return true;
     } else if (d is Variable) {
         Resource dval = evaluate(d, denv);
         if (dval != null) {
             return unify(s, senv, dval, denv, f);
         } else {
             if (f) denv[d] = evaluate(s, senv);
             return true;
         }
     } else if (s.Equals(d)) {
         return true;
     } else {
         return false;
     }
 }