X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=expr.cs;h=3ad5f767f9de40dbea4c9bf2990460e24e11e2c9;hb=5886b86d4068fbd3a1d87d3e19a298689d65c62a;hp=43d6becc3d109c8a98e2e7c8776c611f3f217508;hpb=c25c3228ff23992a3c4f58f83f10af1252de732d;p=m17n%2Fm17n-lib-cs.git diff --git a/expr.cs b/expr.cs index 43d6bec..3ad5f76 100644 --- a/expr.cs +++ b/expr.cs @@ -8,37 +8,34 @@ public class Test { 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.FunctionTable func_table = new MExpression.FunctionTable (); + 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); } }