// cons: creates a list from an expression and an existing list private PLList cons_fun(PLObject a, PLList b) { PLList retval = new PLList(); retval.Add(a); for (int i = 0; i < b.Count; ++i) { retval.Add(b[i]); } return(retval); }
// Evaluate a list of expressions. Return a new list that gives the // value for each expression. private PLList EvalPLList(PLList list, PLEnvironment localEnv, Stream traceStream) { PLList retval = new PLList(); for (int i = 0; i < list.Count; ++i) { retval.Add(Eval(list[i], localEnv, traceStream)); } return(retval); }
// cdr: returns the remainder of a list private PLList cdr_fun(PLList list) { PLList retval = new PLList(); for (int i = 1; i < list.Count; ++i) { retval.Add(list[i]); } return(retval); }
public PLObject GetExpression() { string token = GetToken(); if (token == null) { return(null); } if (token.Equals("'")) { // The "'" character means "quote", and preserve // the next expression. PLList retval = new PLList(); retval.Add(new PLStringAtom("quote")); PLObject nextExpr = GetExpression(); if (nextExpr == null) { throw new Exception("'quote' was not followed by a complete expression"); } retval.Add(nextExpr); return(retval); } if (!token.Equals("(")) { // Not the beginning of a list; the expression is // simply this token. See if it's a number or a // plain string. try { return(new PLNumberAtom(token)); } catch (Exception) { // Just treat it as a regular string return(new PLStringAtom(token)); } } else { // We have the beginning of a list, which can contain // any number of expressions. Keep building our list // until we encounter the closing paren. PLList retval = new PLList(); PLObject nextExpr = GetExpression(); while (!nextExpr.Equals(")")) { retval.Add(nextExpr); nextExpr = GetExpression(); if (nextExpr == null) { throw new Exception("Incomplete expression (unbalanced parens?"); } } return(retval); } }