Comments (7)
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 module/paths
in boot.janet with (dyn *module-paths* module/paths)
I could see possible issues here, but I think it should generally work
from janet.
I was a little surprised that dynamic bindings aren't propagated through imports
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:
As a work around for all recent Janet versions, you can also do (import ./other :env (make-env (curenv)))
. The default was that import, require, and dofile start with a pristine environment, including dynamic bindings when imported. We might want to go back to that.
from janet.
@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 *module/make-env*
people can choose to implement that or other behaviors, so I think it's a good compromise.
from janet.
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?
from janet.
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 use
/require
/import
/etc to work as usual. However when evaluating the scripts which underpin the language being implemented, I want a different module/paths
to be defined. My problem is that module/paths
is a table in root-env
, so I don't know how to change it only for the environment that's used when evaluating the scripts; I don't want it to be different for the main interpreter program.
from janet.
@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 *module/paths*
dynamic binding, I would expect it to work on imports within files I import, too. Though I could definitely see an argument for doing something along those lines with a custom loader instead.
from janet.
This should be fixed as of fdaf2e1 (since revised to *module-make-env*
). I've verified that this can solve the initial issue (albeit with a bit of work) by bypassing the usual flow of (make-env)
to create new environments for files when doing import
, require
, or dofile
.
from janet.
Related Issues (20)
- false branch of `if-let` doesn't report the correct call stack information. HOT 4
- `ev/select` should not resume a dead task. HOT 4
- `try` and `defer` break tail call optimization. HOT 4
- `(= @"update" @"update")` is `false`. HOT 3
- `ev/select` still revives fibers.... HOT 3
- option to unbundle docstrings and potential consequences HOT 8
- splicing into structs/tables HOT 2
- Disasm/asm doesn't round-trip for function with unused argument HOT 1
- eventloop/networking gets stuck on musl HOT 11
- Can it run on iOS? Thank you. HOT 3
- `os/strftime` doesn't respect environment variables. HOT 3
- Re-integrate jpm into janet HOT 49
- recent change kinda breaks lexical scope with multiple modules HOT 2
- How to switch off spork/sh/copy message? HOT 2
- `janet -c source` with missing output files should give informative error message HOT 1
- Linux event loop hanging HOT 7
- Certain PEG patterns don't match HOT 2
- Discrepancy between the website docs and behavior for the `look` peg special HOT 4
- `release-fix` Branch is 5 Commits Behind? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from janet.