public static Exp DeconstructList(this Exp list, IList <string> args, Exp body) { if (args.Count == 2) { return(list.Call(Lambda(new[] { args[0], args[1] }, body))); } var newBody = new Var("tail").DeconstructList(args.Skip(1).ToList(), body); return(list.Call(Lambda(new[] { args[0], "tail" }, newBody))); }
public static Exp PrintText(string text, Exp printSymbol, Exp printGlyphs) { var tokens = text.Split(" ", StringSplitOptions.RemoveEmptyEntries); var symbols = tokens.Select(t => PrintSymbolByName(t, printSymbol)); var symbolsList = List(symbols.ToArray()); return(printGlyphs.Call(symbolsList, 0)); }
public static Exp PrintSymbolByName(string symbol, Exp printSymbol) { var sym = Renderer.Instance.GetSymbolFor(symbol); if (sym.Type == SymbolType.Graphics) { return(List(sym.Pixels.Select(p => Vec(p.X, p.Y)).ToArray())); } return(printSymbol.Call(sym.Type == SymbolType.Name, sym.Code)); }
public static Exp Second(this Exp aPair) => tail.Call(aPair);
public static Exp First(this Exp aPair) => head.Call(aPair);
public static Exp If(Exp cond, Exp t, Exp f) => cond.Call(t, f);
public override Exp Apply(Exp x) { return(x.Call(Head, Tail)); }