public override LispDataType Evaluate(LispInterpreter context)
 {
     if (IsLiteral)
     {
         return(this);
     }
     else
     {
         LispDataType result = context.ExecuteLispFunction(Data).Evaluate(context).Copy();
         return(result);
     }
 }
 public override LispDataType Evaluate(LispInterpreter context)
 {
     if (IsLiteral)
     {
         return(this);
     }
     else
     {
         if (context.LispGlobals.ContainsKey(Value))
         {
             return(context.LispGlobals[Value]);
         }
         else
         {
             throw new LispException(string.Format(ERR_UNDEFINED_VARIABLE, Value));
         }
     }
 }
            public LispDataType Evaluate(List <LispDataType> arguments, LispInterpreter context)
            {
                // replace function arguments
                if (arguments.Count != args.Count)
                {
                    throw new LispException(String.Format(ERR_INVALID_NUMBER_OF_ARGUMENTS, name));
                }

                if (func is LispNumericAtom)
                {
                    return(func.Evaluate(context));
                }
                else if (func is LispList)
                {
                    // Create the argument replacement map.
                    Dictionary <string, LispDataType> argReplacements = new Dictionary <string, LispDataType>();
                    for (int i = 0; i < args.Count; ++i)
                    {
                        LispDataType d = arguments[i].Evaluate(context);
                        if (d is LispList)
                        {
                            argReplacements[args[i].Value] = d.Copy();
                        }
                        else
                        {
                            argReplacements[args[i].Value] = d;
                        }
                    }

                    // Replace the arguments and evaluate.
                    return(((LispList)func).Replace(argReplacements, false).Evaluate(context));
                }
                else
                {
                    if (args.Count >= 1 && args[0].Value == ((LispSymbolicAtom)func).Value)
                    {
                        return(arguments[0].Evaluate(context));
                    }
                    else
                    {
                        return(func.Evaluate(context));
                    }
                }
            }
 public override LispDataType Evaluate(LispInterpreter context)
 {
     return(this);
 }
        private LispSymbolicAtom defun(LispSymbolicAtom name, LispList arguments, LispDataType function, LispInterpreter context)
        {
            List <LispSymbolicAtom> argList = new List <LispSymbolicAtom>();

            foreach (LispDataType arg in arguments)
            {
                if (arg is LispSymbolicAtom)
                {
                    argList.Add((LispSymbolicAtom)arg);
                }
                else
                {
                    throw new LispException(string.Format(ERR_NOT_A_SYMBOL, arg.ToString()));
                }
            }
            LispUserFunctions[name.Value] = new LispUserFunction(name.Value, argList, function);
            LispSymbolicAtom result = new LispSymbolicAtom(name);

            result.SetLiteral(true);
            return(result);
        }