-
Notifications
You must be signed in to change notification settings - Fork 85
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
Make dependencies between files explicit via require/import #211
Comments
Regarding the current set-up: All npm packages are valid WebPPL packages, so you should be able to |
In addition to what Paul said, I do think we should consider making We'd have to think about what the semantics would be. We would definitely want it to be possible to In addition to packages, we'd also want to enable requiring individual js and wppl files (which may in turn recursively require other files). Again, the ability to load webppl files would require an extension beyond node require. Overall, it would be great if we could come up with a solution that (to users) feels as close as possible to how node A related consideration is whether we should introduce |
We could also consider building on the ES6 modules syntax. (Related #239.) I wonder whether at some point we might need to consider using a different syntax to call out to JS so that member expressions are available for use as namespaces for modules. |
Yes, |
I frequently find myself wanting to include various bits of existing deterministic Javascript code in my WebPPL programs: for example, THREE.js, or some miscellaneous utility functions only relevant to my current experiment. It feels cumbersome to me to write a webppl package just to include this code. Do other people have a similar experience, and if so, would it be useful to talk about a principled way to improve the experience?
Ideally, I'd like to just be able to call node.js's
require
function from webppl code. As things stand, this isn't possible because in therun
function insrc/main.js
using
eval.call
makesrequire
unavailable. It turns out thatrequire
is not a member of the global object, but rather a special function that's locally available to every module (https://nodejs.org/api/globals.html#globals_require). Apparently, thethis
argument toeval.call
clobbers the module. Usingeval
directly works, and I checked that all the webppl tests pass when using it instead ofeval.call
. Is there a specific reason why we useeval.call
here?Even with
require
available, I end up having to call it like thisto circumvent the CPS transform. Would people be opposed to omitting
require
from the CPS transform or exposing it some other way (perhaps via a globally-available object, likewebppl.nodeRequire
)?The text was updated successfully, but these errors were encountered: