Code Monkey home page Code Monkey logo

Comments (2)

munificent avatar munificent commented on June 25, 2024

I'm trying to figure out a way to do a node.js-style relative import, but loadModuleFn doesn't seem to be quite enough on its own.

Right, it's context free. You know the import string, but not where it appears.

This is sort of by design, though it may not ultimately be the right design. I like the idea of an import saying what you want to import more so than where you want to go from the current module to find it. Being context-free in that way makes it easier to rearrange files, support package managers, etc.

It's, more or less, how Java, C#, and C/C++ tend to work, if you wave your hands around include paths, classpaths, .cvproj files, etc.

But it can also be tedious and verbose in the presence of a lot of nesting, and it's not clear how the CLI should locate the "root" that absolute imports are imported relative from. (Right now, it's the directory where the main script appears, but that's not ideal.)

The import system in Wren is really rudimentary right now. I wanted to get enough in place to start experimenting. And, more important to me at the time, start playing with the actual runtime semantics of modules and scope. But it definitely needs a lot of work and probably a lot of experimentation.

One option to try might be to have a syntax that means "relative import". Perhaps a leading dot in the import string. Then, when the VM sees that, it prepends the containing module's path. Though, once we do that, we'll want to be able to back out of directories too. We'll likely end up with something like Python's syntax for relative imports.

I'm not sure if that's a good thing or a bad thing. What do you think?

from wren-cli.

Qard avatar Qard commented on June 25, 2024

Yeah, I had actually been thinking ./ for relative and bare to search a wren_modules folder, like node. The relative search doesn't currently work though. :(

from wren-cli.

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.