

namespace Schemin.Primitives.StringOperations
{
	using Schemin.Evaluate;
	using Schemin.AST;
	public class StringLength : Primitive
	{
		public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args)
		{
			ScheminString str = (ScheminString) args.Car;
			ScheminInteger len = new ScheminInteger(str.Value.Length);
			return len;
		}

		public override void CheckArguments(ScheminPair args)
		{
			IScheminType first = args.Car;
			
			if (args.Length != 1)
			{
				throw new BadArgumentsException("expected 1 argument");
			}

			if ((first as ScheminString) == null)
			{
				throw new BadArgumentsException("first argument must be a string");
			}

			return;
		}
	}
}
