private LispList append(LispList list, List <LispDataType> values) { if (values.Count == 0) { return(new LispList(list)); } if (list.IsDotted) { throw new LispException(string.Format(ERR_INVALID_LIST_ENDING, list.Last())); } List <LispDataType> evaluatedData = new List <LispDataType>(values); LispList result = new LispList(list); if (values.First().Evaluate(this) is LispList) { // TODO: ADDRANGE AND VALUES NOT BEING COPIED? result.Data.AddRange(((LispList)values.First().Evaluate(this)).Data); result.IsDotted = list.IsDotted; } else { result.Data.Add(values.First().Evaluate(this)); result.IsDotted = true; } result.SetLiteral(true); return(append(result, values.GetRange(1, values.Count - 1))); }
private LispNumericAtom listlength(LispList list) { if (list.IsDotted) { throw new LispException(string.Format(ERR_INVALID_LIST_ENDING, list.Last())); } return(new LispNumericAtom(list.Count)); }
private LispDataType cdr(LispList list) { if (list.IsAtom) { return(list); } if (list.Count == 2 && list.IsDotted) { return(list.Last()); } return(list.GetRange(1, list.Count - 1)); }
// Return a copy of the list made of the given range. public LispList GetRange(int index, int count) { LispList result = Copy(); result.Data = Data.GetRange(index, count); if (result.Count == 1 && result.IsDotted) { throw new LispException(string.Format(ERR_INVALID_LIST_ENDING, result.Last())); } if (result.Count == 0) { result.IsAtom = true; } return(result); }