Skip to content

Commit

Permalink
Add examples and make compiler output more const
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang committed Dec 13, 2021
1 parent ab683cb commit df0b1c0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/percival/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ fn cmp_new_decls(ctx: &Context) -> (Context, String) {
for result in Rc::clone(&ctx.results).iter() {
let name = ctx.gensym(&format!("{}_new", result));
decls.push(format!(
"let {} = {}.Set().asMutable();",
"const {} = {}.Set().asMutable();",
name, VAR_IMMUTABLE,
));
ctx = ctx.add(VarId::New(result.clone()), name);
Expand Down Expand Up @@ -533,7 +533,7 @@ fn cmp_rule_incremental(

let goal = format!(
"
let {goal} = {imm}.Map({goal_obj});
const {goal} = {imm}.Map({goal_obj});
if (!{set}.includes({goal})) {new}.add({goal});
",
goal = VAR_GOAL,
Expand Down
5 changes: 5 additions & 0 deletions examples/purchased.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all_purchased(buyer) :-
orders_unique(buyer),
num_purchased = count[1] { orders_unique(buyer) },
num_total = count[1] { food() },
`num_purchased === num_total`.
6 changes: 6 additions & 0 deletions examples/rolling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rolling(end_time, average) :-
data(time: end_time),
average = mean[x] {
data(time, x),
`end_time - 7 < time && time <= end_time`
}.

0 comments on commit df0b1c0

Please sign in to comment.