2 using System.Collections;
3 using System.Collections.Generic;
10 public delegate object MEvaluator (MExpression args);
12 public class MFunction
14 internal readonly MSymbol name;
15 internal readonly MEvaluator evaluator;
16 public static Dictionary<MSymbol, MFunction> CommonTable
17 = new Dictionary<MSymbol, MFunction> ();
19 public MFunction (MSymbol name, MEvaluator evaluator)
21 this.evaluator = evaluator;
22 CommonTable[name] = this;
25 public MFunction (MSymbol name, MEvaluator evaluator,
26 Dictionary<MSymbol, MFunction> dict)
28 this.evaluator = evaluator;
32 public object Call (MExpression args)
34 return evaluator (args);
37 private object plus (MExpression args)
40 foreach (MExpression expr in args)
41 n += expr.Eval (bindings);
45 private object multiply (MExpression args)
48 foreach (MExpression expr in args)
49 n *= expr.Eval (bindings);
56 int n = - Plist.Eval (env);
57 foreach (MPlist plist in Plist.next)
58 n -= plist.Eval (env);
63 int n = Plist.Eval (env);
64 foreach (MPlist plist in Plist.next)
65 n /= plist.Eval (env);
70 return Plist.Eval (env) % Plist.next.Eval (env);
74 return Plist.Eval (env) | Plist.next.Eval (env);
78 return Plist.Eval (env) & Plist.next.Eval (env);
82 return Plist.Eval (env) << Plist.next.Eval (env);
86 return Plist.Eval (env) >> Plist.next.Eval (env);
90 MSymbol var = (MSymbol) Plist.val;
96 public class MBindings : MPlist
98 public MBindings () : base () { }
100 public new MBindings Push (MSymbol variable, object value)
102 base.Push (variable, value);
105 public override string ToString ()
108 foreach (MBindings b in this)
112 str += b.key + " = " + b.val;
118 public class MExpression : MPlist
120 public MExpression () : base () { }
122 public MExpression Append (MFunction func, MExpression args)
124 base.Add (op, (MPlist) args);
128 public object Eval ()