Giter Site home page Giter Site logo

Comments (6)

bakpakin avatar bakpakin commented on May 24, 2024 2

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.

bakpakin avatar bakpakin commented on May 24, 2024 1

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.

pepe avatar pepe commented on May 24, 2024

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.

afranchuk avatar afranchuk commented on May 24, 2024

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.

afranchuk avatar afranchuk commented on May 24, 2024

@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.

bakpakin avatar bakpakin commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.