public static IEnumerable <string> Variables(IExpr expr) { if (expr.IsSymbol()) { yield return(expr.SymbolValue()); } if (expr.IsFunc()) { var func = expr as Function; if (!func.IsBinary) { foreach (var variable in Variables(func.FirstArgument)) { yield return(variable); } } else { foreach (var variable in Variables(func.FirstArgument).Concat(Variables(func.SecondArgument))) { yield return(variable); } } } }
public static IEnumerable<string> Variables(IExpr expr) { if (expr.IsSymbol()) yield return expr.SymbolValue(); if (expr.IsFunc()) { var func = expr as Function; if (!func.IsBinary) { foreach(var variable in Variables(func.FirstArgument)) yield return variable; } else { foreach (var variable in Variables(func.FirstArgument).Concat(Variables(func.SecondArgument))) yield return variable; } } }