Code Monkey home page Code Monkey logo

Comments (5)

spy16 avatar spy16 commented on May 24, 2024 1

Check out the MapScope implementation in https://github.com/spy16/sabre/tree/namespaced-scope.. I did a simple implementation of Clojure like Namespaces (Has ns to switch namespace, has *ns* that resolves to current namespace name). This does not support sub-namespaces and it is more like Go packages. Let me know your thoughts.

I have also used / as namespace separator because, i do want to add support for method invocation and . is more conventional approach for that.

Note: I haven't merged this to master and haven't decided wether I should merge or not as well. Like you said, not yet sure if this should exist as part of sabre package itself or not.

from sabre.

spy16 avatar spy16 commented on May 24, 2024

I've been thinking about this too. Importing files is definitely needed. And that would require some isolation between imported things. May be some basic version of namespaces should be done in sabre itself.

One simple approach you can use is to implement scope interface and make sure everything passed to Bind call is done with ns/name format. You can even support automatic resolution of namespace. For example, if user enters only foo you resolve this to current-ns/foo in your Scope implementation. Same trick goes for imported files. Implement import function that uses filename or a ns header and binds all the values from the file with that namespace.

from sabre.

lthibault avatar lthibault commented on May 24, 2024

May be some basic version of namespaces should be done in sabre itself.

Sure, that would be helpful, especially if the facilities provided by Sabre are minimal and unopinionated.

Specifically, I don't think Sabre should force any particular syntax upon the user. I'm deliberately trying to avoid Clojure's import-path syntax, which mixes various types of separators (e.g.: (clojure.core/refer-clojure)), and do something more like this: namespace.sub_namespace.some_function.

Maybe Sabre should just provide an example of your suggested implementation (e.g. in the REPL rather than the sabre namespace) ? It seems like a good first-step that doesn't close any doors.

from sabre.

lthibault avatar lthibault commented on May 24, 2024

Ok, after thinking about this some more, I'm still stuck. This is very much a language design issue, but if you have any insights, I'd be most appreciative!

What you describe above solves the problem of encapsulating symbols within a namespace, and it makes perfect sense. I'm still stuck on the second piece of the puzzle, though: how can I implement the switching of the current namespace?

In Clojure, I can create a new namespace and set it as the current namespace (= *ns*) as follows:

user=> (ns my.new.namespace)
nil
my.new.namespace=>

Do you have any insights on how this might work in Sabre?

(I think this is where it might make sense for Sabre to provide some functionality ... maybe.)

from sabre.

lthibault avatar lthibault commented on May 24, 2024

Closing this as it's largely addressed by the example in branch slang.

from sabre.

Related Issues (17)

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.