private IEnumerable <Object> GetSubexpressions(ConsCell args) { try { return(args.GetListItems()); } catch (System.InvalidOperationException) { throw new SyntaxException("Syntax error: Invalid expression."); } }
public IEnumerable <Object> GetListItems() { ConsCell current = this; while (true) { if (current == Nil) { yield break; } yield return(current.Car); if (!(current.Cdr is ConsCell)) { throw new System.InvalidOperationException("This is not a list."); } current = (ConsCell)current.Cdr; } }