<commit_before>
namespace Schemin.Evaluate
{
	using System;
	using System.Text;
	using System.Collections;
	using System.Collections.Generic;
	using System.Linq;
	using Schemin.AST;
	using Schemin.Evaluate.Primitives;

	public class Evaluator
	{
		private Type integer = typeof(ScheminInteger);
		private Type atom = typeof(ScheminAtom);
		private Type list = typeof(ScheminList);
		private Type str = typeof(ScheminString);
		private Type primitive = typeof(ScheminPrimitive);
		private Type lambda = typeof(ScheminLambda);
		private Type boolean = typeof(ScheminBool);

		public EvaluatorState EvalState = EvaluatorState.Normal;

		public IScheminType Evaluate(ScheminList ast, Environment env)
		{
			IScheminType last = null;

			foreach (IScheminType type in ast)
			{
				last = EvaluateInternal(type, env);
			}

			return last;
		}

		public IScheminType EvaluateInternal(IScheminType ast, Environment env)
		{
			if ((ast as IScheminNumeric) != null)
			{
				return ast;
			}
			else if ((ast as ScheminString) != null)
			{
				return ast;
			}
			else if ((ast as ScheminBool) != null)
			{
				return ast;
			}
			else if ((ast as ScheminAtom) != null)
			{
				return EvalAtom(ast, env);
			}
			else if ((ast as ScheminPrimitive) != null)
			{
				return ast;
			}
			else if ((ast as ScheminLambda) != null)
			{
				return ast;
			}
			else if ((ast as ScheminList) != null)
			{
				ScheminList evalList = (ScheminList) ast;
				ScheminList complete = new ScheminList();

				if (IsEmptyList(ast))
				{
					return ast;
				}

				foreach (IScheminType type in evalList)
				{
					if ((type as IScheminNumeric) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminString) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminBool) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminAtom) != null)
					{
						IScheminType atomResult = EvalAtom(type, env);
						complete.Append(atomResult);
					}
					else if ((type as ScheminPrimitive) != null)
					{
						ScheminPrimitive prim = (ScheminPrimitive) type;
						SetStatePrimitive(prim);
						complete.Append(type);
					}
					else if ((type as ScheminLambda) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminList) != null)
					{
						switch (this.EvalState)
						{
							case EvaluatorState.LambdaArgs:
							case EvaluatorState.QuoteArgs:
							case EvaluatorState.LetArgs:
							case EvaluatorState.IfArgs:
							case EvaluatorState.CondArgs:
							case EvaluatorState.DefineArgs:
							case EvaluatorState.AndArgs:
							case EvaluatorState.OrArgs:
								complete.Append(type);
								continue;
						}

						IScheminType listResult = EvaluateInternal(type, env);
						complete.Append(listResult);
					}
				}

				IScheminType functionPosition = complete.Car();
				ScheminList functionArgs = complete.Cdr();

				if ((functionPosition as ScheminPrimitive) != null)
				{
					ScheminPrimitive prim = (ScheminPrimitive) functionPosition;
					return prim.Evaluate(functionArgs, env, this);
				}
				else if ((functionPosition as ScheminLambda) != null)
				{
					ScheminLambda lam = (ScheminLambda) functionPosition;
					return lam.Evaluate(functionArgs, this);
				}
				else
				{
					throw new InvalidOperationException("Non-function in function position: " + functionPosition.ToString());
				}
			}
			else
			{
				// something weird happened
				return ast;
			}
		}


		public IScheminType EvalAtom(IScheminType ast, Environment env)
		{
			switch (this.EvalState)
			{
				case EvaluatorState.DefineArgs:
					// only ignore the FIRST symbol after a define
					this.EvalState = EvaluatorState.Normal;
					return ast;
				case EvaluatorState.LambdaArgs:
				case EvaluatorState.LetArgs:
				case EvaluatorState.IfArgs:
				case EvaluatorState.CondArgs:
				case EvaluatorState.QuoteArgs:
				case EvaluatorState.SetBangArgs:
					// only ignore the first argument to set!
					this.EvalState = EvaluatorState.Normal;
					return ast;
			}

			ScheminAtom temp = (ScheminAtom) ast;

			IScheminType bound = GetEnvValue(temp, env);
			if (bound == null)
			{
				throw new UnboundAtomException(string.Format("Unbound atom: {0}", temp));
			}


			return bound;
		}

		public bool IsEmptyList(IScheminType type)
		{
			if (type.GetType() == typeof(ScheminList))
			{
				ScheminList temp = (ScheminList) type;
				if (temp.Empty == true)
				{
					return true;
				}
			}

			return false;<commit_msg>Make it not totally broken<commit_after>
namespace Schemin.Evaluate
{
	using System;
	using System.Text;
	using System.Collections;
	using System.Collections.Generic;
	using System.Linq;
	using Schemin.AST;
	using Schemin.Evaluate.Primitives;

	public class Evaluator
	{
		private Type integer = typeof(ScheminInteger);
		private Type atom = typeof(ScheminAtom);
		private Type list = typeof(ScheminList);
		private Type str = typeof(ScheminString);
		private Type primitive = typeof(ScheminPrimitive);
		private Type lambda = typeof(ScheminLambda);
		private Type boolean = typeof(ScheminBool);

		public EvaluatorState EvalState = EvaluatorState.Normal;

		public IScheminType Evaluate(ScheminList ast, Environment env)
		{
			IScheminType last = null;

			foreach (IScheminType type in ast)
			{
				last = EvaluateInternal(type, env);
			}

			return last;
		}

		public IScheminType EvaluateInternal(IScheminType ast, Environment env)
		{
			if ((ast as IScheminNumeric) != null)
			{
				return ast;
			}
			else if ((ast as ScheminString) != null)
			{
				return ast;
			}
			else if ((ast as ScheminBool) != null)
			{
				return ast;
			}
			else if ((ast as ScheminAtom) != null)
			{
				return EvalAtom(ast, env);
			}
			else if ((ast as ScheminPrimitive) != null)
			{
				return ast;
			}
			else if ((ast as ScheminLambda) != null)
			{
				return ast;
			}
			else if ((ast as ScheminList) != null)
			{
				ScheminList evalList = (ScheminList) ast;
				ScheminList complete = new ScheminList();

				if (IsEmptyList(ast))
				{
					return ast;
				}

				foreach (IScheminType type in evalList)
				{
					if ((type as IScheminNumeric) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminString) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminBool) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminAtom) != null)
					{
						IScheminType atomResult = EvalAtom(type, env);
						complete.Append(atomResult);
					}
					else if ((type as ScheminPrimitive) != null)
					{
						ScheminPrimitive prim = (ScheminPrimitive) type;
						SetStatePrimitive(prim);
						complete.Append(type);
					}
					else if ((type as ScheminLambda) != null)
					{
						complete.Append(type);
					}
					else if ((type as ScheminList) != null)
					{
						switch (this.EvalState)
						{
							case EvaluatorState.LambdaArgs:
							case EvaluatorState.QuoteArgs:
							case EvaluatorState.LetArgs:
							case EvaluatorState.IfArgs:
							case EvaluatorState.CondArgs:
							case EvaluatorState.DefineArgs:
							case EvaluatorState.AndArgs:
							case EvaluatorState.OrArgs:
								complete.Append(type);
								continue;
						}

						IScheminType listResult = EvaluateInternal(type, env);
						complete.Append(listResult);
					}
				}

				IScheminType functionPosition = complete.Car();
				ScheminList functionArgs = complete.Cdr();

				if ((functionPosition as ScheminPrimitive) != null)
				{
					ScheminPrimitive prim = (ScheminPrimitive) functionPosition;
					return prim.Evaluate(functionArgs, env, this);
				}
				else if ((functionPosition as ScheminLambda) != null)
				{
					ScheminLambda lam = (ScheminLambda) functionPosition;
					return lam.Evaluate(functionArgs, this);
				}
				else
				{
					throw new InvalidOperationException("Non-function in function position: " + functionPosition.ToString());
				}
			}
			else
			{
				// something weird happened
				return ast;
			}
		}


		public IScheminType EvalAtom(IScheminType ast, Environment env)
		{
			switch (this.EvalState)
			{
				case EvaluatorState.DefineArgs:
					// only ignore the FIRST symbol after a define
					this.EvalState = EvaluatorState.Normal;
					return ast;
				case EvaluatorState.LambdaArgs:
				case EvaluatorState.LetArgs:
				case EvaluatorState.IfArgs:
				case EvaluatorState.CondArgs:
				case EvaluatorState.QuoteArgs:
					return ast;
				case EvaluatorState.SetBangArgs:
					// only ignore the first argument to set!
					this.EvalState = EvaluatorState.Normal;
					return ast;
			}

			ScheminAtom temp = (ScheminAtom) ast;

			IScheminType bound = GetEnvValue(temp, env);
			if (bound == null)
			{
				throw new UnboundAtomException(string.Format("Unbound atom: {0}", temp));
			}


			return bound;
		}

		public bool IsEmptyList(IScheminType type)
		{
			if (type.GetType() == typeof(ScheminList))
			{
				ScheminList temp = (ScheminList) type;
				if (temp.Empty == true)
				{
					return true;
				}
			}

			return false;
{'fraction_non_alphanumeric': 0.09729551451187335, 'fraction_numerical': 0.00021987686895338611, 'mean_word_length': 2.7809642560266004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4428791', 'n_tokens_mistral': 3860, 'n_tokens_neox': 2834, 'n_words': 719}