@Override public T next() { T head = l.head(); l = (scala.collection.immutable.List<T>) l.tail(); return head; } };
@Override public T next() { T head = l.head(); l = (scala.collection.immutable.List<T>) l.tail(); return head; } };
Map<Pair<Integer, Integer>, List<Pair<scala.collection.immutable.List<Pair<Integer, Integer>>, Term>>> commonPath = rewrites.stream().collect(Collectors.groupingBy(rw -> rw.getLeft().head()));
/** * goes down the path on the subject to find the rewrite place, does the substitution, and reconstructs the term * on its way up */ private Term buildRHS(Term subject, Substitution<Variable, Term> substitution, scala.collection.immutable.List<Pair<Integer, Integer>> path, Term rhs, TermContext context) { if (path.isEmpty()) { return rhs.substituteAndEvaluate(substitution, context); } else { if (subject instanceof KItem) { KItem kItemSubject = (KItem) subject; List<Term> newContents = new ArrayList<>(((KList) kItemSubject.kList()).getContents()); //noinspection RedundantCast newContents.set(path.head().getLeft(), buildRHS(newContents.get(path.head().getLeft()), substitution, (scala.collection.immutable.List<Pair<Integer, Integer>>) path.tail(), rhs, context)); return KItem.of(kItemSubject.kLabel(), KList.concatenate(newContents), context.global()).applyAnywhereRules(context); } else if (subject instanceof BuiltinList) { BuiltinList builtinListSubject = (BuiltinList) subject; List<Term> newContents = new ArrayList<>(builtinListSubject.children); //noinspection RedundantCast newContents.set(path.head().getLeft(), buildRHS(newContents.get(path.head().getLeft()), substitution, (scala.collection.immutable.List<Pair<Integer, Integer>>) path.tail(), rhs, context)); return BuiltinList .builder(builtinListSubject.sort, builtinListSubject.operatorKLabel, builtinListSubject.unitKLabel, builtinListSubject.globalContext()) .addAll(newContents) .build(); } else { throw new AssertionError("unexpected rewrite in subject: " + subject); } } }
/** * Creates a new `Spool` of given `elems`. */ @SuppressWarnings("unchecked") public static <T> Spool<T> newSpool(Collection<T> elems) { List<T> buffer = (List<T>)List.empty(); for (T item : elems) { buffer = buffer.$colon$colon(item); } Spool<T> result = (Spool<T>)EMPTY; while(!buffer.isEmpty()){ result = new Spool.Cons<T>(buffer.head(), Future.value(result)); buffer = (List<T>)buffer.tail(); } return result; }
/** * Creates a new `Spool` of given `elems`. */ @SuppressWarnings("unchecked") public static <T> Spool<T> newSpool(Collection<T> elems) { List<T> buffer = (List<T>)List.empty(); for (T item : elems) { buffer = buffer.$colon$colon(item); } Spool<T> result = (Spool<T>)EMPTY; while(!buffer.isEmpty()){ result = new Spool.Cons<T>(buffer.head(), Future.value(result)); buffer = (List<T>)buffer.tail(); } return result; }