Skip to content
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

Namespaces in macros #154

Open
porky11 opened this issue Nov 25, 2016 · 0 comments
Open

Namespaces in macros #154

porky11 opened this issue Nov 25, 2016 · 0 comments

Comments

@porky11
Copy link
Contributor

porky11 commented Nov 25, 2016

It would be nice to be able to get the namespace in introspection
Needed functions:
(symbol-namespace mc name) returns namespace of a variable or extern-c function
(symbol-namespace mc name args) returns namespace of a function or macro called with args
(current-namespace mc) returns the current namespace used by macro
(parent-namespace mc namespace) returns the parent namespace of a namespace

Some macro, that would be useful too:
since . means root namespace .. may mean parent-namespace too

(using-namespace std.macros
(import macros)
(import cstdlib)

(def debug (macro intern (name rest) ;;use some debug-version of the function
  (def args (var auto \ (get-varargs-list mc (- (arg-count mc) 1) rest)))
  (def namespace (symbol-namespace name args)) ;;namespace of a symbol which takes args as arguments
  (if (not (null args))
    (qq using-namespace (uq namespace)
      (uql args))
    (do
      (make-node mc)))))

(namespace a
  (def a (fn intern void (void)
    (printf "a\n")))
  (namespace debug
    (def a (macro intern (rest)
      (printf "called a with wrong number of arguments\n")
      (exit 1)
      (make-node mc)))))
)
(def main (fn extern-c void (void)
  (using-namespace a
  (using-namespace b
    (debug a)
    (debug a 1))))

This was referenced Nov 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant