2024-01-26 05:37:51 +00:00
|
|
|
namespace KumiScript.Interpreter
|
|
|
|
{
|
2024-07-12 00:17:00 +00:00
|
|
|
public class ProperListExpression : Expression
|
2024-01-26 05:37:51 +00:00
|
|
|
{
|
|
|
|
readonly List<Expression> _values;
|
|
|
|
public ProperListExpression(List<Expression> expressions)
|
|
|
|
{
|
|
|
|
_values = expressions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Expression Eval(Environment env)
|
|
|
|
{
|
2024-07-12 00:17:00 +00:00
|
|
|
Expression rator = Car().Eval(env);
|
|
|
|
Expression rand = Cdr();
|
2024-01-26 05:37:51 +00:00
|
|
|
return rator.Apply(rand, env);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override List<Expression> EvalMembers(Environment env)
|
|
|
|
{
|
|
|
|
List<Expression> result = new List<Expression>();
|
|
|
|
for (int i = 0; i < _values.Count; i++)
|
|
|
|
result.Add(_values[i].Eval(env));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override List<Expression> GetMembers()
|
|
|
|
{
|
|
|
|
return _values;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2024-07-12 00:17:00 +00:00
|
|
|
return string.Concat("(",
|
|
|
|
string.Join(' ', (object[]) _values.ToArray()),
|
2024-01-26 05:37:51 +00:00
|
|
|
")");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Expression Car()
|
|
|
|
{
|
|
|
|
return _values.First();
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:17:00 +00:00
|
|
|
public override Expression Cdr()
|
2024-01-26 05:37:51 +00:00
|
|
|
{
|
|
|
|
List<Expression> rest = new List<Expression>(_values);
|
|
|
|
rest.RemoveAt(0);
|
|
|
|
return ListFactory.MakeList(rest);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override ProperListExpression Cons(Expression expr)
|
|
|
|
{
|
|
|
|
List<Expression> consd = new List<Expression>(_values);
|
|
|
|
consd.Insert(0, expr);
|
|
|
|
return new ProperListExpression(consd);
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:17:00 +00:00
|
|
|
public override ProperListExpression AppendToList(Expression expr)
|
2024-01-26 05:37:51 +00:00
|
|
|
{
|
2024-07-12 00:17:00 +00:00
|
|
|
List<Expression> appended = new List<Expression>(_values);
|
|
|
|
appended.Append(expr);
|
|
|
|
return new ProperListExpression(appended);
|
2024-01-26 05:37:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|