public LithpFunctionDefinitionNative(LithpAtom name, string[] parameters, LithpFunctionDefinitionDelegate body) { fn_name = name; fn_params = parameters; fn_body = body; Match x = Regex.Match(name, @"/(\d+|\*)$"); if (x == Match.Empty) { arity = fn_params.Count(); this.fn_name = LithpAtom.Atom(name.Name + "/" + arity.Value.ToString()); } else { string strArity = x.Groups[1].Value; if (strArity == "*") { arity = null; } else { arity = int.Parse(strArity); } } }
protected ILithpOpChainMember mapParamInner(JValue v, LithpOpChain chain, string fnName) { Classification cls = classify(v); string strV = v.ToString(); parserDebug("Classified: {0}", cls.ToString()); if (cls.HasFlag(Classification.STRING_DOUBLE) || cls.HasFlag(Classification.STRING_SINGLE)) { strV = strV.Substring(1, strV.Length - 2); string parsed = LithpParser.ParseEscapes(strV); if (cls.HasFlag(Classification.STRING_DOUBLE)) { return(new LithpLiteral(new LithpString(parsed))); } else if (cls.HasFlag(Classification.STRING_SINGLE)) { return(LithpAtom.Atom(parsed)); } } else if (cls.HasFlag(Classification.VARIABLE)) { switch (fnName) { case "get": case "set": case "var": return(new LithpVariableReference(strV)); default: return(LithpFunctionCall.New("get/1", new LithpVariableReference(strV))); } } else if (cls.HasFlag(Classification.NUMBER)) { if (cls.HasFlag(Classification.NUMBER_INTEGER)) { return(new LithpLiteral(new LithpInteger(strV))); } else if (cls.HasFlag(Classification.NUMBER_FLOAT)) { return(new LithpLiteral(new LithpFloat(strV))); } else { throw new NotImplementedException(); } } else if (cls.HasFlag(Classification.ATOM)) { return(new LithpLiteral(LithpAtom.Atom(strV))); } throw new NotImplementedException(); }