{
static MSymbol Mpreedit = MSymbol.Of ("preedit");
- public static object insert (object[] args, MPlist bindings)
+ public static object insert (MExpression[] args, MExpression.Domain domain)
{
- object arg = ((MExpression) args[0]).Eval (bindings);
- MPlist slot = bindings.Find (Mpreedit);
- MText preedit = (MText) slot.val;
+ MText preedit = (MText) domain.GetValue (Mpreedit);
+ object val = args[0].Val;
- if (arg is int)
- preedit.Cat ((int) arg);
+ if (val is int)
+ preedit.Cat ((int) val);
else
- preedit.Cat ((MText) arg);
- return arg;
+ preedit.Cat ((MText) val);
+ return val;
}
public static void Main()
{
- MExpression expr;
- MPlist bindings = new MPlist ();
MExpression.Domain domain = new MExpression.Domain (null);
- MExpression.Defun (func_table, "insert", new MExpression.Evaluator (insert),
- 1, 1, typeof (MExpression));
- bindings.Add (MSymbol.Of ("X"), 10);
- bindings.Add (Mpreedit, new MText ("PREEDIT TEXT"));
+ domain.Defun ("insert", insert, 1, 1, false);
+ domain.Bind (MSymbol.Of ("X"), 10);
+ domain.Bind (Mpreedit, new MText ("PREEDIT TEXT"));
+ MExpression expr;
using (FileStream stream = new FileStream ("eval.txt", FileMode.Open))
{
- expr = new MExpression (new MPlist (stream), func_table);
+ expr = new MExpression (new MPlist (stream), domain);
}
- Console.WriteLine (bindings);
- expr.PrettyPrint ();
- Console.WriteLine ("\n => " + expr.Eval (bindings, null));
- Console.WriteLine (bindings);
+ Console.WriteLine (domain);
+ Console.Write (expr);
+ Console.WriteLine (" => " + expr.Eval (domain));
+ Console.WriteLine (domain);
}
}