fn cmp_rule_incremental(
    ctx: &Context,
    rule: &Rule,
    update_position: Option<usize>,
) -> Result<String> {
    let mut ctx = ctx.clone();

    let mut clauses = Vec::new();
    for (i, clause) in rule.clauses.iter().enumerate() {
        let only_update = update_position == Some(i);
        clauses.push(cmp_clause(&mut ctx, clause, only_update, false)?);
    }

    let goal = format!(
        "
const {goal} = {imm}.Map({goal_obj});
if (!{set}.includes({goal})) {new}.add({goal});
",
        goal = VAR_GOAL,
        imm = VAR_IMMUTABLE,
        goal_obj = cmp_fields(&ctx, &rule.goal.props)?,
        set = ctx.get(&VarId::Set(rule.goal.name.clone())).unwrap(),
        new = ctx.get(&VarId::New(rule.goal.name.clone())).unwrap(),
    );

    let mut code = String::from("{\n");
    for clause in &clauses {
        code += clause;
        code += "\n";
    }
    code += goal.trim();
    code += &"\n}".repeat(clauses.len() + 1);
    Ok(code)
}
/// Compile a single incremental semi-naive evaluation loop for a rule.
Compile a single incremental semi-naive evaluation loop for a rule.
Compile a single incremental semi - naive evaluation loop for a rule .
fn cmp_rule_incremental(
    ctx: &Context,
    rule: &Rule,
    update_position: Option<usize>,
) -> Result<String> {
    let mut ctx = ctx.clone();
    let mut clauses = Vec::new();
    for (i, clause) in rule.clauses.iter().enumerate() {
        let only_update = update_position == Some(i);
        clauses.push(cmp_clause(&mut ctx, clause, only_update, false)?);
    }
    let goal = format!(
        "
const {goal} = {imm}.Map({goal_obj});
if (!{set}.includes({goal})) {new}.add({goal});
",
        goal = VAR_GOAL,
        imm = VAR_IMMUTABLE,
        goal_obj = cmp_fields(&ctx, &rule.goal.props)?,
        set = ctx.get(&VarId::Set(rule.goal.name.clone())).unwrap(),
        new = ctx.get(&VarId::New(rule.goal.name.clone())).unwrap(),
    );
    let mut code = String::from("{\n");
    for clause in &clauses {
        code += clause;
        code += "\n";
    }
    code += goal.trim();
    code += &"\n}".repeat(clauses.len() + 1);
    Ok(code)
}
fn cmp_rule_incremental ( ctx : & Context , rule : & Rule , update_position : Option < usize > , ) -> Result < String > { let mut ctx = ctx . clone ( ) ; let mut clauses = Vec :: new ( ) ; for ( i , clause ) in rule . clauses . iter ( ) . enumerate ( ) { let only_update = update_position == Some ( i ) ; clauses . push ( cmp_clause ( & mut ctx , clause , only_update , false ) ? ) ; } let goal = format ! ( " " goal VAR_GOAL imm VAR_IMMUTABLE goal_obj cmp_fields ( ctx rule goal props ) set ctx get ( VarId Set ( rule goal name clone ( ) ) ) unwrap ( ) new ctx get ( VarId New ( rule goal name clone ( ) ) ) unwrap ( ) ) ; let mut code = String :: from ( " \n " ) ; for clause in & clauses { code += clause ; code += " \n " ; } code += goal . trim ( ) ; code += & " \n " . repeat ( clauses . len ( ) + 1 ) ; Ok ( code ) }
Compile a single incremental semi-naive evaluation loop for a rule.
Compile a single incremental semi - naive evaluation loop for a rule .
ctx
&Context
rule
&Rule
update_position
Option<usize>
ctx
&Context
rule
&Rule
update_position
Option<usize>