public static IEnumerable <ISExpression> Flatten(this ISExpression s) { var ss = new List <ISExpression>(); if (s.IsNil()) { ss.Add(s); return(ss); } var ok = s is Cons; while (ok) { var c = s as Cons; ss.Add(c.Car); s = c.Cdr; ok = s is Cons; } if (s != AtomHelper.Nil) { throw new InvalidOperationException("list is not flat"); } return(ss); }
public static bool IsList(this ISExpression sexpr) { var c = sexpr as Cons; return(sexpr.IsNil() || (c != null && (c.Cdr.IsNil() || c.Cdr.IsList()))); }