use of suite.fp.match.Matchers.IF in project suite by stupidsing.
the class InterpretFunLazy method lazy.
public Thunk_ lazy(Node node) {
Node parsed = parse(node);
Map<String, Thunk_> df = new HashMap<>();
df.put(TermOp.AND___.name, binary((a, b) -> new Pair_(a, b)));
df.put("fst", () -> new Fun_(in -> ((Pair_) in.get()).first_));
df.put("if", () -> new Fun_(a -> () -> new Fun_(b -> () -> new Fun_(c -> a.get() == Atom.TRUE ? b : c))));
df.put("snd", () -> new Fun_(in -> ((Pair_) in.get()).second));
for (Entry<Operator, IntInt_Bool> e : TreeUtil.boolOperations.entrySet()) {
IntInt_Bool fun = e.getValue();
df.put(e.getKey().getName(), binary((a, b) -> b(fun.apply(compare(a.get(), b.get()), 0))));
}
for (Entry<Operator, IntInt_Int> e : TreeUtil.intOperations.entrySet()) {
IntInt_Int fun = e.getValue();
df.put(e.getKey().getName(), binary((a, b) -> Int.of(fun.apply(i(a), i(b)))));
}
List<String> keys = df.keySet().stream().sorted().collect(Collectors.toList());
Lazy_ lazy0 = new Lazy_(0, IMap.empty());
Frame frame = new Frame(null);
for (String key : keys) {
lazy0 = lazy0.put(Atom.of(key));
frame.add(df.get(key));
}
return lazy0.lazy_(parsed).apply(frame);
}
Aggregations