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

Handle dependencies between webppl headers #318

Open
hawkrobe opened this issue Feb 10, 2016 · 2 comments
Open

Handle dependencies between webppl headers #318

hawkrobe opened this issue Feb 10, 2016 · 2 comments
Labels

Comments

@hawkrobe
Copy link
Contributor

In our basic package system, you can include a list of webppl header files in your package.json file:

{
  "name": "testModule",
  "webppl": {
    "wppl" : ["header1.wppl", "header2.wppl"]
  }
}

For many refactoring schemes, you'll want to define variables or functions in one header and use them in the other, e.g.

// header1.wppl
var a = 1;
// header2.wppl
var b = a + 1

and then b is assigned to 2 in your main code.

Currently, whether this works or not depends entirely on the order that you write the two files in package.json. The order written above works, because header1.wppl is appended first, but if you swap the order, e.g.

{
  "name": "testModule",
  "webppl": {
    "wppl" : ["header2.wppl", "header1.wppl"]
  }
}

then b is NaN in the main code.

The way we handle dependencies between webppl headers should be order-independent, and would optimally be able to handle mutual dependencies as well, e.g. if header1.wppl also defined a variable c in terms of b

@stuhlmueller
Copy link
Member

I think we'd be best off emulating node's require to make dependencies between .wppl (and also .js) files explicit. See my proposal here.

However, in the meantime, relying on the order in package.json doesn't seem terrible. Have you run into cases where this is a serious obstacle? (We should document it, though.)

@hawkrobe
Copy link
Contributor Author

I agree that's the best solution. I've always felt uncomfortable calling functions that are defined in some .wppl header, since it's not obvious from reading the code which package they come from, or what header inside that package...

My problem was just that I didn't realize the order mattered, so no I haven't run into any cases where (intentionally) relying on order is a serious obstacle. It's just not obvious from the package documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants