예제 #1
0
        public static Object Nconc(Cons args, Environment environment)
        {
            // With no argument, returns null
            if (args == null)
            {
                return(null);
            }

            // With one argument, returns that argument
            if (args.Length() < 2)
            {
                return(args.First());
            }

            for (int i = 0; i < args.Length() - 1; i++)
            {
                Cons cons = (Cons)args.Nth(i);
                cons = (Cons)cons.Last();
                cons.Rplacd(args.Nth(i + 1));
            }

            return(args.First());
        }
예제 #2
0
        /// <summary>
        /// (nconc list*)
        /// Returns a list whose elements are the elements of each list in
        /// order. Destructively modifies all but the last list, such that
        /// the cdr of the last cons in each list is the next list.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public static Object Nconc(Cons args, Environment environment)
        {
            // With no argument, returns null
            if (args == null)
                return null;

            // With one argument, returns that argument
            if (args.Length() < 2)
                return args.First();

            for (int i = 0; i < args.Length() -1; i ++)
            {
                Cons cons = (Cons)args.Nth(i);
                cons = (Cons)cons.Last();
                cons.Rplacd(args.Nth(i+1));
            }

            return args.First();
        }
예제 #3
0
		/// <summary>
		/// (defmethod name "arg1 arg2" "(expression1)" "(expression 2)" [...])
		/// Created methods used for DefClass <br />
		/// </summary>
		/// <param name="args"></param>
		/// <param name="e"></param>
		/// <returns></returns>
		public static object DefMethod(Cons args, Environment e)
		{
			string name;
			string[] _args;
			string commands = "";
			name = args.First().ToString();
			_args = args.Second().ToString().Split(new string[] {" "}, StringSplitOptions.None);;
			for (int i = 2; i < args.Length(); i++)
				commands += args.Nth(i) + " ";
			commands = commands.Replace("\\", "\\\\");
			commands = commands.Replace("\"", "\\\"");
			//FIXME: 
			//code = code.Replace("\n", "\\n");
			DefinedMethod ret = new DefinedMethod(commands, name, _args);
			e.AssignLocal(Symbol.FromName(name), ret);
			Console.WriteLine("Assigned '" + ret.Name + "' as a DefinedMethod");
			return ret;
		}
예제 #4
0
		/// <summary>
		/// Creates a dynamic class
		/// (defclass "classname" "inheritsfrom" [defmethod]) 
		/// e.g. (defclass "class1" "Object" DefinedMethods*)
		/// </summary>
		/// <param name="args"></param>
		/// <param name="environment"></param>
		/// <returns></returns>
		public static Object DefClass(Cons args, Environment environment) 
		{
			string className = args.First().ToString();
			string superClass = args.Second().ToString();
			
			DefinedMethod[] methods = new DefinedMethod[args.Length() - 2];
			for (int i = 2; i < args.Length(); i++) 
			{
				try {
					Symbol toFind = (Symbol) args.Nth(i);
					object foundMethod =  environment.GetValue(toFind);
					methods[i - 2] = (DefinedMethod) foundMethod;
				} catch (Exception e ) {
					Console.WriteLine("DEFCLASS ERROR: " + e.Message + " " + e.StackTrace);
				}
			}
			return ClassBuilder.CreateClass(className, superClass, "", methods);
		}