Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript preamble not working properly #49

Open
erlanger opened this issue Oct 18, 2018 · 0 comments
Open

Javascript preamble not working properly #49

erlanger opened this issue Oct 18, 2018 · 0 comments

Comments

@erlanger
Copy link

Not working in the playground

err1

TypeError: replacement.expr is undefined chrworker.js:20:5

Must be a problem with the parser, maybe.

Failing also in node, in a different way

Using JS preamble:

{
  // preamble
  // code in this block can be used in the rules' guards and bodies

  function print (v) {
    console.log(v)
  }

  function pred (v) {
    return v < 5
  }
}

print_num     @ num(v) ==> ${ (v) => print(v) }
generate_nums @ num(v) ==> ${ (v) => pred(v) } | num(v+1)
//generate_nums @ num(v) ==> v < 5 | num(v+1)

produces this output:

1
ID  Constraint
--  ----------
1   num(1)

Should produce a sequence of numbers.

Works when using chr guards without calling javascript:

{
  // preamble
  // code in this block can be used in the rules' guards and bodies

  function print (v) {
    console.log(v)
  }

  function pred (v) {
    return v < 5
  }
}

print_num     @ num(v) ==> ${ (v) => print(v) }
//generate_nums @ num(v) ==> ${ (v) => pred(v) } | num(v+1) <--- commented out
generate_nums @ num(v) ==> v < 5 | num(v+1)

Produces the correct output:

1
2
3
4
5
ID  Constraint
--  ----------
1   num(1)
2   num(2)
3   num(3)
4   num(4)
5   num(5)

For reference the javascript calling code:

var chr = require('./t.js')
function pr() {
 console.log(chr.Store.toString()) 
}
chr.num(1).then(pr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant