From 6d8a681beabbfb0e5c6e5903780b4d9d59c8ddba Mon Sep 17 00:00:00 2001 From: handa Date: Thu, 6 Aug 2009 13:11:16 +0000 Subject: [PATCH] *** empty log message *** --- MExpression.cs | 632 +++++++++++++++++++++++++++----------------------------- 1 file changed, 299 insertions(+), 333 deletions(-) diff --git a/MExpression.cs b/MExpression.cs index 2acb104..9d446d0 100644 --- a/MExpression.cs +++ b/MExpression.cs @@ -9,8 +9,76 @@ namespace M17N.Core { public class MExpression { - public delegate object Evaluator (object[] args, MPlist bindings, - object context); + public class Domain + { + internal Mplist functions = new MPlist (); + internal MPlist bindings = new MPlist (); + internal object context; + + public Domain (object context) + { + this.context = context; + } + + public Domain (Domain parent, object context) : this (context) + { + functions = parent.functions; + bindings = parent.bindings; + } + + public void Bind (MSymbol sym, object value) + { + bindings = bindings.Cons (sym, value); + } + + public void Defun (string name, Evaluator evaluator, + int min_arg, ArgType arg_type) + { + MSymbol sym = MSymbol.Of (name); + Function func = new Function (sym, evaluator, min_arg, arg_type); + + functions = functions.Cons (sym, func); + } + + public void Defmacro (string name, MPlist args, MPlist body) + { + MSymbol sym = MSymbol.Of (name); + Function func = new Function (sym, new Lambda (args, body)); + + functions = functions.Cons (sym, func); + } + + private Function GetFunc (MSymbol name) + { + Function func = functions.Get (name); + + if (func == null) + throw new Exception ("Unknown function: " + name); + return func; + } + + private object GetValue (MSymbol name) + { + MPlist slot = bindings.Find (name); + + if (slot == null) + throw new Exception ("Unbound variable: " + name); + return slot.val; + } + + private void SetValue (MSymbol name, object val) + { + MPlist slot = bindings.Find (name); + + if (slot == null) + bindings = bindings.Cons (var, null); + else + slot.val = val; + return val; + } + } + + public delegate object Evaluator (object[] args, Domain domain); internal delegate void PrettyPrinter (Function func, string indent, object[] args); @@ -24,11 +92,42 @@ namespace M17N.Core internal class Function { + private class Lambda + { + internal readonly MSymbol[] args; + internal readonly MExpression[] body; + + public Lambda (MPlist args, MPlist body) + { + int len; + + len = args.Count; + this.args = new MSymbol[len]; + for (int i = 0; ! args.IsEmpty; i++, args = args.next) + this.args[i] = args.Symbol; + len = body.Count; + this.body = new MExpression[len]; + for (int i = 0; ! body.IsEmpty; i++, body = body.next) + { + if (body.IsSymbol) + this.body[i] = new MExpression (body.Symbol); + else if (body.IsMText) + this.body[i] = new MExpression (body.Text); + else if (body.IsIntegeer) + this.body[i] = new MExpression (body.Integer); + else if (body.IsPlist) + this.body[i] = new MExpression (body.plist); + else + throw new Exception ("Invalid expression: " + body); + } + } + } + internal readonly MSymbol name; internal readonly Evaluator eval; internal readonly int min_arg; internal readonly ArgType arg_type; - internal object[] data; + internal readonly Lambda lambda; public PrettyPrinter pp; @@ -37,18 +136,24 @@ namespace M17N.Core internal static Function literal, varref, block, defun; public Function (MSymbol name, Evaluator eval, - int min_arg, enum ArgType arg_type) + int min_arg, ArgType arg_type) { this.name = name; this.eval = eval; this.min_arg = min_arg; this.arg_type = arg_type; - if (min_arg == 2 && arg_type = ArgType.FIXED) + if (min_arg == 2 && arg_type == ArgType.FIXED) pp = set_pretty_printer; else pp = default_pretty_printer; } + public Function (MSymbol name, Lambda lambda) + { + this.name = name; + this.lambda = lambda; + } + static Function () { default_pretty_printer = new PrettyPrinter (default_pp); @@ -56,58 +161,6 @@ namespace M17N.Core literal = Defun ("nil", null, 1, 1); varref = Defun ("symbol", new Evaluator (get_value), 1, 1); block = Defun ("plist", new Evaluator (progn), 1, -1); - - Defun ("set", new Evaluator (set_value), 2, 2, - typeof (MSymbol), typeof (MExpression)); - Defun ("=", new Evaluator (set_value), 2, 2, - typeof (MSymbol), typeof (MExpression)); - Defun ("+", new Evaluator (plus), 1, -1); - Defun ("*", new Evaluator (multi), 2, -1); - Defun ("-", new Evaluator (minus), 1, -1); - Defun ("/", new Evaluator (divide), 2, -1); - Defun ("%", new Evaluator (percent), 2, -1); - Defun ("|", new Evaluator (logior), 2, -1); - Defun ("&", new Evaluator (logand), 2, -1); - Defun ("+=", new Evaluator (pluseq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("*=", new Evaluator (multieq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("-=", new Evaluator (minuseq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("/=", new Evaluator (divideeq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("%=", new Evaluator (percenteq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("|=", new Evaluator (logioreq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("&=", new Evaluator (logandeq), 2, -1, - typeof (MSymbol), typeof (MExpression)); - Defun ("<<", new Evaluator (lshift), 2, 2); - Defun (">>", new Evaluator (rshift), 2, 2); - Defun ("<<=", new Evaluator (lshifteq), 2, 2, - typeof (MSymbol), typeof (MExpression)); - Defun (">>=", new Evaluator (rshifteq), 2, 2, - typeof (MSymbol), typeof (MExpression)); - Defun ("==", new Evaluator (eq), 2, -1); - Defun ("!=", new Evaluator (noteq), 2, 2); - Defun ("<", new Evaluator (less), 2, -1); - Defun ("<=", new Evaluator (lesseq), 2, -1); - Defun (">", new Evaluator (more), 2, -1); - Defun (">=", new Evaluator (moreeq), 2, -1); - block = Defun ("progn", new Evaluator (progn), 1, -1); - block.pp = new PrettyPrinter (block_pp); - Defun ("cond", new Evaluator (cond), 1, -1, - typeof (MExpression[])).pp = new PrettyPrinter (cond_pp); - Defun ("if", new Evaluator (ifclause), 2, -1, - typeof (MExpression)).pp = new PrettyPrinter (if_pp); - Defun ("while", new Evaluator (whileclause), 1, -1, - typeof (MExpression)).pp = new PrettyPrinter (while_pp); - defun = Defun ("defun", new Evaluator (define_function), 4, -1, - typeof (FunctionTable), - typeof (MSymbol), - typeof (MPlist), - typeof (MExpression)); - defun.pp = new PrettyPrinter (defun_pp); } private static MPlist find_binding (object[] args, MPlist bindings) @@ -162,334 +215,327 @@ namespace M17N.Core ((MExpression) args[1]).pp (indent); Console.Write (")"); } + } - private static object get_value (object[] args, MPlist bindings, - object context) - { - return find_binding (args, bindings).val; - } + private static Domain basic; - private static object set_value (object[] args, MPlist bindings, - object context) - { - MSymbol var = (MSymbol) args[0]; - MPlist slot = bindings.Find (var); + static MExpression () + { + default_domain = new Domain (null); + + literal = Defun ("nil", null, 1, 1); + varref = Defun ("symbol", new Evaluator (get_value), 1, 1); + block = Defun ("plist", new Evaluator (progn), 1, -1); + + basic.Defun ("set", new Evaluator (set_value), 2, ArgType.UNEVALLED); + basic.Defun ("=", new Evaluator (set_value), 2, ArgType.UNEVALLED); + basic.Defun ("+", new Evaluator (plus), 2, ArgType.MANY); + basic.Defun ("*", new Evaluator (multi), 2, ArgType.MANY); + basic.Defun ("-", new Evaluator (minus), 1, ArgType.MANY); + basic.Defun ("/", new Evaluator (divide), 2, ArgType.MANY); + basic.Defun ("%", new Evaluator (percent), 2, ArgType.MANY); + basic.Defun ("|", new Evaluator (logior), 2, ArgType.MANY); + basic.Defun ("&", new Evaluator (logand), 2, ArgType.MANY); + basic.Defun ("+=", new Evaluator (pluseq), 2, ArgType.MANY); + basic.Defun ("*=", new Evaluator (multieq), 2, ArgType.MANY); + basic.Defun ("-=", new Evaluator (minuseq), 2, ArgType.MANY); + basic.Defun ("/=", new Evaluator (divideeq), 2, ArgType.MANY); + basic.Defun ("%=", new Evaluator (percenteq), 2, ArgType.MANY); + basic.Defun ("|=", new Evaluator (logioreq), 2, ArgType.MANY); + basic.Defun ("&=", new Evaluator (logandeq), 2, ArgType.MANY); + basic.Defun ("<<", new Evaluator (lshift), 2, ArgType.FIXED); + basic.Defun (">>", new Evaluator (rshift), 2, ArgType.FIXED); + basic.Defun ("<<=", new Evaluator (lshifteq), 2, ArgType.FIXED); + basic.Defun (">>=", new Evaluator (rshifteq), 2, ArgType.FIXED); + basic.Defun ("==", new Evaluator (eq), 2, ArgType.MANY); + basic.Defun ("!=", new Evaluator (noteq), 2, ArgType.FIXED); + basic.Defun ("<", new Evaluator (less), 2, ArgType.MANY); + basic.Defun ("<=", new Evaluator (lesseq), 2, ArgType.MANY); + basic.Defun (">", new Evaluator (more), 2, ArgType.MANY); + basic.Defun (">=", new Evaluator (moreeq), 2, ArgType.MANY); + basic.Defun ("progn", new Evaluator (progn), 0, ArgType.UNEVALLED); + basic.Defun ("cond", new Evaluator (cond), 1, ArgType.UNEVALLED); + basic.Defun ("if", new Evaluator (ifclause), 2, ArgType.UNEVALLED); + basic.Defun ("while", new Evaluator (whileclause), 1, ArgType.UNEVALLED); + basic.Defun ("defun", new Evaluator (defun), 2, ArgType.UNEVALLED); + } - if (slot == null) - slot = bindings.Push (var, null); - slot.val = ((MExpression) args[1]).Eval (bindings, context); - if (slot.val is MText) - slot.val = ((MText) slot.val).Dup (); - return slot.val; - } + private static object get_value (object[] args, Domain domain) + { + return domain.GetValue ((MSymbol) args[0]); + } - private static object plus (object[] args, MPlist bindings, - object context) - { - object val = ((MExpression) args[0]).Eval (bindings, context); + private static object set_value (object[] args, Domain domain) + { + return domain.SetValue ((MSymbol) args[0], + MExpression.Eval (args[1], domain)); + } - if (val is int) - { - int n = 0; - foreach (MExpression e in args) - n += (int) e.Eval (bindings, context); - val = n; - } - else if (val is MText) - { - MText mt = new MText (); - foreach (MExpression e in args) - mt += (MText) e.Eval (bindings, context); - val = mt; - } - return val; - } + private static object plus (object[] args, Domain domain) + { + if (args[0] is int) + { + int n = 0; + foreach (int i in args) + n += i; + return n; + } + else if (args[0] is MText) + { + MText mt = new MText (); + foreach (MText m in args) + mt += m; + return mt; + } + throw new Exception ("Not an integer nor MText: " + args[0]); + } - private static object multi (object[] args, MPlist bindings, - object context) + private static object multi (object[] args, Domain domain) { int n = 1; - foreach (MExpression e in args) - n *= (int) e.Eval (bindings, context); + foreach (int i in args) + n *= i; return n; } - private static object minus (object[] args, MPlist bindings, - object context) + private static object minus (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; if (args.Length == 1) return - n; for (int i = 1; i < args.Length; i++) - n -= (int) ((MExpression) args[i]).Eval (bindings, context); + n -= (int) args[i]; return n; } - private static object divide (object[] args, MPlist bindings, - object context) + private static object divide (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; for (int i = 1; i < args.Length; i++) - n /= (int) ((MExpression) args[i]).Eval (bindings, context); + n /= (int) args[i]; return n; } - private static object percent (object[] args, MPlist bindings, - object context) + private static object percent (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; for (int i = 1; i < args.Length; i++) - n %= (int) ((MExpression) args[i]).Eval (bindings, context); + n %= (int) args[i]; return n; } - private static object logior (object[] args, MPlist bindings, - object context) + private static object logior (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); - for (int i = 1; i < args.Length; i++) - n |= (int) ((MExpression) args[i]).Eval (bindings, context); + int n = 0; + foreach (int i in args) + n |= i; return n; } - private static object logand (object[] args, MPlist bindings, - object context) + private static object logand (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); - for (int i = 1; i < args.Length; i++) - n &= (int) ((MExpression) args[i]).Eval (bindings, context); + int n = 0; + foreach (int i in args) + n &= i; return n; } - private static object pluseq (object[] args, MPlist bindings, - object context) + private static object pluseq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - object val = slot.val; + MSymbol sym = (MSymbol) args[0]; + object val = domain.GetValue (sym); if (val is int) { int n = (int) val; for (int i = 1; i < args.Length; i++) - n += (int) ((MExpression) args[i]).Eval (bindings, context); - slot.val = n; + n += (int) MExpression.Eval (args[i], domain); + val = n; } else if (val is MText) { MText mt = (MText) val; for (int i = 1; i < args.Length; i++) - mt.Cat ((MText) ((MExpression) args[i]).Eval (bindings, context)); + mt.Cat ((MText) MExpression.Eval (args[i], domain)); + val = mt; } - return slot.val; + return domain.SetValue (sym, val); } - private static object multieq (object[] args, MPlist bindings, - object context) + private static object multieq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n = (int) slot.val; + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + for (int i = 1; i < args.Length; i++) - n *= (int) ((MExpression) args[i]).Eval (bindings, context); - return (slot.val = n); + n *= (int) MExpression.Eval (args[i], domain); + return domain.SetValue (sym, (object) n); } - private static object minuseq (object[] args, MPlist bindings, - object context) + private static object minuseq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n = (int) slot.val; + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + for (int i = 1; i < args.Length; i++) - n -= (int) ((MExpression) args[i]).Eval (bindings, context); - return (slot.val = n); + n -= (int) MExpression.Eval (args[i], domain); + return domain.SetValue (sym, (object) n); } - private static object divideeq (object[] args, MPlist bindings, - object context) + private static object divideeq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n = (int) slot.val; + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + for (int i = 1; i < args.Length; i++) - n /= (int) ((MExpression) args[i]).Eval (bindings, context); - return (slot.val = n); + n /= (int) MExpression.Eval (args[i], domain); + return domain.SetValue (sym, (object) n); } - private static object percenteq (object[] args, MPlist bindings, - object context) + private static object percenteq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n = (int) slot.val; + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + for (int i = 1; i < args.Length; i++) - n %= (int) ((MExpression) args[i]).Eval (bindings, context); - return (slot.val = n); + n %= (int) MExpression.Eval (args[i], domain); + return domain.SetValue (sym, (object) n); } - private static object logioreq (object[] args, MPlist bindings, - object context) + private static object logioreq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n = (int) slot.val; + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + for (int i = 1; i < args.Length; i++) - n |= (int) ((MExpression) args[i]).Eval (bindings, context); - return (slot.val = n); + n |= (int) MExpression.Eval (args[i], domain); + return domain.SetValue (sym, (object) n); } - private static object logandeq (object[] args, MPlist bindings, - object context) + private static object logandeq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n = (int) slot.val; + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + for (int i = 1; i < args.Length; i++) - n &= (int) ((MExpression) args[i]).Eval (bindings, context); - return (slot.val = n); + n &= (int) MExpression.Eval (args[i], domain); + return domain.SetValue (sym, (object) n); } - private static object lshift (object[] args, MPlist bindings, - object context) + private static object lshift (object[] args, Domain domain) { - int n1 = (int) ((MExpression) args[0]).Eval (bindings, context); - int n2 = (int) ((MExpression) args[1]).Eval (bindings, context); - return n1 << n2; + return (int) args[0] << (int) args[1]; } - private static object lshifteq (object[] args, MPlist bindings, - object context) + private static object lshifteq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n1 = (int) slot.val; - int n2 = (int) ((MExpression) args[1]).Eval (bindings, context); - return (slot.val = (n1 << n2)); + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + + n <<= (int) MExpression.Eval (args[1], domain); + return domain.SetValue (sym, (object) n); } - private static object rshift (object[] args, MPlist bindings, - object context) + private static object rshift (object[] args, Domain domain) { - int n1 = (int) ((MExpression) args[0]).Eval (bindings, context); - int n2 = (int) ((MExpression) args[1]).Eval (bindings, context); - return n1 >> n2; + return (int) args[0] >> (int) args[1]; } - private static object rshifteq (object[] args, MPlist bindings, - object context) + private static object rshifteq (object[] args, Domain domain) { - MPlist slot = find_binding (args, bindings); - int n1 = (int) slot.val; - int n2 = (int) ((MExpression) args[1]).Eval (bindings, context); - return (slot.val = (n1 >> n2)); + MSymbol sym = (MSymbol) args[0]; + int n = (int) domain.GetValue (sym); + + n >>= (int) MExpression.Eval (args[1], domain); + return domain.SetValue (sym, (object) n); } - private static object eq (object[] args, MPlist bindings, - object context) + private static object eq (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; + for (int i = 1; i < args.Length; i++) - if (n != (int) ((MExpression) args[i]).Eval (bindings, context)) - return 0; - return 1; + if (n != (int) args[i]) + return false; + return true; } - private static object noteq (object[] args, MPlist bindings, - object context) + private static object noteq (object[] args, Domain domain) { - int n1 = (int) ((MExpression) args[0]).Eval (bindings, context); - int n2 = (int) ((MExpression) args[1]).Eval (bindings, context); - return (n1 != n2); + return ((int) args[0] != (int) args[1]); } - private static object less (object[] args, MPlist bindings, - object context) + private static object less (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; + for (int i = 1; i < args.Length; i++) { - int n1 = (int) ((MExpression) args[i]).Eval (bindings, context); + int n1 = (int) args[i]; if (n >= n1) - return 0; + return false; n = n1; } - return 1; + return true; } - private static object lesseq (object[] args, MPlist bindings, - object context) + private static object lesseq (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; for (int i = 1; i < args.Length; i++) { - int n1 = (int) ((MExpression) args[i]).Eval (bindings, context); + int n1 = (int) args[i]; if (n > n1) - return 0; + return false; n = n1; } - return 1; + return true; } - private static object more (object[] args, MPlist bindings, - object context) + private static object more (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; for (int i = 1; i < args.Length; i++) { - int n1 = (int) ((MExpression) args[i]).Eval (bindings, context); + int n1 = (int) args[i]; if (n <= n1) - return 0; + return false; n = n1; } - return 1; + return true; } - private static object moreeq (object[] args, MPlist bindings, - object context) + private static object moreeq (object[] args, Domain domain) { - int n = (int) ((MExpression) args[0]).Eval (bindings, context); + int n = (int) args[0]; for (int i = 1; i < args.Length; i++) { - int n1 = (int) ((MExpression) args[i]).Eval (bindings, context); + int n1 = (int) args[i]; if (n < n1) - return 0; + return false; n = n1; } - return 1; + return true; } - private static object progn (object[] args, MPlist bindings, - object context) + private static object progn (object[] args, Domain domain) { - object result = null; + object result = false; - foreach (MExpression e in args) - result = e.Eval (bindings, context); + foreach (MPlist p in args) + result = MExpression.Eval (o, domain); return result; } - private static void block_pp (Function func, - string indent, object[] args) - { - bool first = true; - - Console.Write ("("); - indent += " "; - foreach (MExpression e in args) - { - if (first) - first = false; - else - Console.Write ("\n" + indent); - e.pp (indent); - } - Console.Write (")"); - } - - private static bool check_condition (MExpression e, MPlist bindings, - object context) + private static bool check_condition (object condition, Domain domain) { - object result = e.Eval (bindings, context); + object result = MExpression.Eval (condition, context); return (! (result is int) || (int) result != 0); } - private static object cond (object[] args, MPlist bindings, - object context) + private static object cond (object[] args, Domain domain) { - foreach (MExpression[] elist in args) + foreach (MPlist p in args) if (check_condition (elist[0], bindings, context)) { object result = 0; @@ -522,8 +568,7 @@ namespace M17N.Core Console.Write (")"); } - private static object ifclause (object[] args, MPlist bindings, - object context) + private static object ifclause (object[] args, Domain domain) { object result = 0; @@ -551,8 +596,7 @@ namespace M17N.Core Console.Write (")"); } - private static object whileclause (object[] args, MPlist bindings, - object context) + private static object whileclause (object[] args, Domain domain) { object result = 0; @@ -583,8 +627,7 @@ namespace M17N.Core Console.Write (")"); } - public static object define_function (object[] args, MPlist bindings, - object context) + public static object define_function (object[] args, Domain domain) { FunctionTable table = (FunctionTable) args[0]; MSymbol sym = (MSymbol) args[1]; @@ -622,85 +665,8 @@ namespace M17N.Core } Console.Write (")"); } - } - - public class FunctionTable - { - internal Dictionary table; - - public FunctionTable () - { - table = new Dictionary (); - } - public FunctionTable (FunctionTable table) - { - this.table = new Dictionary (table.table); - } - public void Copy (FunctionTable table) - { - foreach (KeyValuePair kv in this.table) - table.table[kv.Key] = kv.Value; - } - - public void Copy (MSymbol name, FunctionTable table) - { - Function func; - if (this.table.TryGetValue (name, out func)) - table.table[name] = func; - } - } - - private static FunctionTable basic_table = new FunctionTable (); - - public static void Defun (FunctionTable table, string name, - Evaluator evaluator, int min_arg, - enum ArgType arg_type) - { - Function func = Defun (name, evaluator, min_arg, arg_type); - table.table[func.name] = func; - } - - public static void Defmacro (FunctionTable table, MSymbol name, - MExpression expr) - { - object[] args = new object[4]; - args[0] = table; - args[1] = name; - args[2] = new MPlist (); - args[3] = expr; - Function.define_function (args, null, null); - } - - private static Function Defun (string name, Evaluator evaluator, - int min_arg, enum ArgType arg_type) - { - MSymbol sym = MSymbol.Of (name); - Function func = new Function (sym, evaluator, min_arg, arg_type); - basic_table.table[sym] = func; - return func; - } - - private static Function Defun (string name, Evaluator evaluator, - int min_arg, enum ArgType arg_type) - { - return Defun (name, evaluator, min_arg, arg_type, typeof (MExpression)); - } - - private static Function Find (MSymbol name, FunctionTable table) - { - if (name == MSymbol.integer - || name == MSymbol.mtext) - return Function.literal; - - Function func; - if ((table == null - || ! table.table.TryGetValue (name, out func)) - && ! basic_table.table.TryGetValue (name, out func)) - return null; - return func; - } private static void invalid_expression (object o) { -- 1.7.10.4