// e.g. hasWord($x) => bla // to: for $x where hasWord($x): bla sO ai_lhsToForWhere(BasicLogicRule rule, DeepZipTools tools) { ret ai_lhsToForWhere(rule, null, tools); } sO ai_lhsToForWhere(BasicLogicRule rule, Set knownVars, DeepZipTools tools) { rule = (BasicLogicRule) ai_fragmentExpressionsToFunctionCalls(rule, tools); if (!(rule.lhs instanceof FunctionCall)) ret rule; FunctionCall fc = (FunctionCall) rule.lhs; if (l(fc.args) != 1) ret rule; O var = first(fc.args); if (!tools.isVar(var) || contains(knownVars, var)) ret rule; ret ForWhere(var, rule.lhs, rule.rhs); }