internal class Lambda : Function
{
- internal Xex[] args;
+ internal bool args_evaled = true;
+ internal Name[] args;
internal Xex[] body;
- public Lambda (Name name, int min_arg, int max_arg)
- : base (name, min_arg, max_arg)
- {
- }
-
- public void SetArgs (XmlNode node, int nargs, Domain domain)
+ public Lambda (XmlNode node)
{
+ Name name = node.Attributes[Nfname].Value;
+ int nargs = 0, noptions = 0, nrest = 0;
+ XmlNode n;
+
+ node = node.FirstChild;
+ if (node != null && node.Name == Nargs)
+ {
+ for (XmlNode 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;
+
+
args = new Xex[nargs];
node = node.FirstChild;
for (int i = 0; i < nargs; node = node.NextSibling)
= new Function.SpecialForm (builtin, name, min_arg, max_arg);
}
- private static Name ParseHead (XmlNode node,
- out int min_arg, out int max_arg)
+ private static Name ParseHead (XmlNode node, out bool evaled,
+ out int min_arg, out int max_arg)
{
Name name = node.Attributes[Nfname].Value;
int nargs = 0, noptions = 0, nrest = 0;
internal Function.Lambda RegisterFunction (XmlNode node)
{
+ bool evaled;
int min_arg, max_arg;
- Name name = ParseHead (node, out min_arg, out max_arg);
+ Name name = ParseHead (node, out evaled, out min_arg, out max_arg);
Function.Lambda lambda = new Function.Lambda (name, min_arg, max_arg);
functions[name] = lambda;
TYPE = 'integer' | 'string' | 'boolean' | 'symbol' | 'list'
DEFUN =
- '<defun fname="' FUNCNAME '">'
+ '<defun fname="' FUNCNAME ? ">'
ARGS ?
TERM *
'</defun>'
ARGS =
- '<args>' [ SYMBOL | VAR ] * OPTIONAL ? REST ? '</args>'
+ '<args>' SYMBOL * OPTIONAL ? REST ? '</args>'
+ | '<unevaled-args>' SYMBOL * OPTIONAL ? REST ? '</args>'
OPTIONAL =
- '<optional/>' [ SYMBOL | VAR ] *
+ '<optional/>' SYMBOL *
REST =
- '<rest/>' [ SYMBOL | VAR ]
+ '<rest/>' SYMBOL
DEFVAR = DEFVAR-INT DEFVAR-STR DEFVAR-BOOL