this.max_arg = max_arg;
}
- public virtual object Call (Xex[] args, Domain domain)
- {
- object result;
-
- Console.Write ("calling (" + this);
- foreach (Xex a in args)
- Console.Write (" " + a);
- Console.Write (") => ");
- result = builtin (args, domain);
- Console.WriteLine (result);
- return result;
- }
+ public abstract object Call (Xex[] args, Domain domain);
public override string ToString ()
{
- return str;
+ return name;
}
internal class Subroutine : Function
public override object Call (Xex[] args, Domain domain)
{
+ object result;
+
foreach (Xex a in args)
if (a.Eval (domain) == null)
throw new Exception (a + ":evaled to null");
- return base.Call (args, domain);
+ Console.Write ("calling (" + this);
+ foreach (Xex a in args)
+ Console.Write (" " + a);
+ Console.Write (") => ");
+ result = builtin (args, domain);
+ Console.WriteLine (result);
+ return result;
}
}
public override object Call (Xex[] args, Domain domain)
{
+ object result;
+
+ Console.Write ("calling (" + this);
+ foreach (Xex a in args)
+ Console.Write (" " + a);
+ Console.Write (") => ");
+ result = builtin (args, domain);
+ Console.WriteLine (result);
+ return result;
}
}
public void Setup (XmlNode node, Domain domain)
{
- lambda = new Lambda ();
node = node.FirstChild;
if (node.Name == Nargs)
{
SetBody (node, domain);
}
- public static Name ParseHead (XmlNode node,
- out int min_arg, out int max_arg)
- {
- Name name = node.Attributes[Nfname].Value;
- int nargs = 0, noptions = 0, nrest = 0;
- XmlNode n;
-
- for (n = node.FirstChild; n != null; n = n.NextSibling)
- {
- if (n.Name == Noptional || n.Name == Nrest)
- break;
- nargs++;
- }
- if (n != null && n.Name == Noptional)
- for (n = n.NextSibling; n != null; n = n.NextSibling)
- {
- if (n.Name == Nrest)
- break;
- noptions++;
- }
- if (n != null && n.Name == Nrest)
- for (n = n.NextSibling; n != null; n = n.NextSibling)
- nrest++;
- min_arg = nargs;
- max_arg = nargs + noptions + nrest;
- if (nrest == 1)
- max_arg = - max_arg;
- return name;
- }
-
public override object Call (Xex[] args, Domain domain)
{
Bindings current = domain.bindings;
public override string ToString ()
{
- str = "(" + name;
+ string str = "(" + name;
foreach (Xex a in args)
str += " " + a;
- str += ")";
+ return (str + ")");
}
}
}
= new Function.SpecialForm (builtin, name, min_arg, max_arg);
}
+ private static Name ParseHead (XmlNode node,
+ out int min_arg, out int max_arg)
+ {
+ Name name = node.Attributes[Nfname].Value;
+ int nargs = 0, noptions = 0, nrest = 0;
+ XmlNode n;
+
+ for (n = node.FirstChild; n != null; n = n.NextSibling)
+ {
+ if (n.Name == Noptional || n.Name == Nrest)
+ break;
+ nargs++;
+ }
+ if (n != null && n.Name == Noptional)
+ for (n = n.NextSibling; n != null; n = n.NextSibling)
+ {
+ if (n.Name == Nrest)
+ break;
+ noptions++;
+ }
+ if (n != null && n.Name == Nrest)
+ for (n = n.NextSibling; n != null; n = n.NextSibling)
+ nrest++;
+ min_arg = nargs;
+ max_arg = nargs + noptions + nrest;
+ if (nrest == 1)
+ max_arg = - max_arg;
+ return name;
+ }
+
internal Function.Lambda RegisterFunction (XmlNode node)
{
int min_arg, max_arg;
- Name name = Function.ParseHead (node, out min_arg, out max_arg);
- Lambda lambda = new Function.Lambda (name, min_arg, max_arg);
+ Name name = ParseHead (node, out min_arg, out max_arg);
+ Function.Lambda lambda = new Function.Lambda (name, min_arg, max_arg);
functions[name] = lambda;
- return func;
+ return lambda;
}
internal Function Defun (XmlNode node)