-
Notifications
You must be signed in to change notification settings - Fork 214
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
Consider making module/paths
a dynamic variable
#1434
Comments
I may be mistaken, but as dynamics are part of the environment your idea doesn't make sense to me. May you please elaborate your use case? |
Yeah, let me be more specific. I'm writing a program in janet which loads/evaluates other janet scripts (it uses janet as a scripting language behind another programming language). So the main interpreter program needs |
I actually did an experiment where module/paths, module/loaders, etc. were only defaults for dynamic bindings, and never merged in since nobody every asked for it and it seemed to make things a little more confusing. The code is simple, add some dynamic bindings, and replace all uses of I could see possible issues here, but I think it should generally work |
@bakpakin On a related note though (and maybe this should be a separate issue?), I was a little surprised that dynamic bindings aren't propagated through imports. It makes sense that e.g. the current environment isn't (so that each file has a consistent base environment when loaded, not based on the load location), however the nature/purpose of dynamic bindings made me think I could do something like # main.janet
(setdyn :foo 'bar)
(import ./other)
(assert (= other/foo 'bar))
# other.janet
(def foo (dyn :foo)) I think this is related to this issue since, if I set the |
This now works on the latest master @afranchuk a bit belated, but does this work for you? (with-dyns [*module/cache* @{}
*module/loading* @{}]
(import ./other)) EDIT: |
This should be fixed as of fdaf2e1 (since revised to |
@bakpakin thanks, that should work great! FWIW your original change wasn't quite what I expected, as I was thinking that only dynamic bindings would be present in imports (not normal bindings) by their nature. But with |
I'm trying to run some code that has a full
root-env
but has a different set of module paths than the main program. Right now I don't think this is possible without redefining all module-loading-related functions (e.g.require
,use
, etc) because any changes tomodule/paths
will affect both the main program environment and the "isolated" version of the environment (the alternate environment to use with specific loaded code, in my case). For that matter, you could probably make the same argument formodule/loaders
/module/cache
being dynamic variables, too.If I'm making some poor assumption and there is a way to do this, let me know! I'm still pretty new to Janet.
Also I realize this might be a bit more complicated than it seems, because e.g. making them dynamic variables would interact poorly with fibers by default (as far as I understand).
The text was updated successfully, but these errors were encountered: