public static Symbol VariableRangeConflict = "variable-range-conflict";
public static Symbol VariableWrongRange = "variable-wrong-range";
public static Symbol VariableWrongValue = "variable-wrong-value";
+
public static Symbol UnknownFunction = "unknown-function";
public static Symbol MacroExpansionError = "macro-expansion-error";
public static Symbol NoVariableName = "no-variable-anme";
internal void ThrowSymbol (Term tag)
{
+ int i = catch_count;
foreach (CatchTag elt in catch_stack)
{
- catch_count--;
+ i--;
if (elt.Tag.Matches (tag))
- return;
+ {
+ catch_count = i;
+ return;
+ }
}
throw new Error (Error.UncaughtThrow,
"No corresponding catch: {0}", tag);
internal Variable Defvar (Symbol name)
{
- Variable vari = new Variable (this, name, Zero);
- variables[name] = vari;
+ Variable vari;
+
+ if (variables.TryGetValue (name, out vari))
+ {
+ Variable.Typed typed = vari as Variable.Typed;
+ if (typed != null)
+ throw new Error (Error.VariableTypeConflict,
+ "Not a non-typed variable: {0}", name);
+ }
+ else
+ {
+ vari = new Variable (this, name, Zero);
+ variables[name] = vari;
+ }
return vari;
}
private static Term Fand (Domain domain, Variable vari, Term[] args)
{
foreach (Term arg in args)
- if (! arg.Eval (domain).IsTrue)
- return Zero;
+ {
+ Term result = arg.Eval (domain);
+ if (domain.Thrown ())
+ result;
+ if (! result.IsTrue)
+ return Zero;
+ }
return One;
}
private static Term For (Domain domain, Variable vari, Term[] args)
{
foreach (Term arg in args)
- if (arg.Eval (domain).IsTrue)
- return One;
+ {
+ Term result = arg.Eval (domain);
+ if (domain.Thrown ())
+ return result;
+ if (result.IsTrue)
+ return One;
+ }
return Zero;
}
Term result = One;
foreach (Term arg in args)
- result = arg.Eval (domain);
+ {
+ result = arg.Eval (domain);
+ if (domain.Thrown ())
+ return result;
+ }
return result;
}
private static Term Fif (Domain domain, Variable vari, Term[] args)
{
- if (args[0].Eval (domain).IsTrue)
+ Term result = args[0].Eval (domain);
+
+ if (domain.Thrown)
+ return result;
+ if (result.IsTrue)
return args[1].Eval (domain);
if (args.Length == 2)
return Zero;
private static Term Fwhen (Domain domain, Variable vari, Term[] args)
{
- if (! args[0].Eval (domain).IsTrue)
+ Term result = args[0].Eval (domain);
+
+ if (domain.Thrown)
+ return result;
+ if (! result.IsTrue)
return Zero;
- Term result = One;
+ result = One;
for (int i = 1; i < args.Length; i++)
- result = args[i].Eval (domain);
+ {
+ result = args[i].Eval (domain);
+ if (domain.Thrown)
+ return result;
+ }
return result;
}
{
result = terms[i].Eval (domain);
if (domain.Thrown (out caught))
- break;
+ return result;
}
return result;
}