I believe this is not currently exposed, although it may be worth pointing out that any internal variable from an imported module is readable with `MyModule.foo`. Julia modules are closed after declaration, although you can sort of cheat by calling `MyModule.eval(::Expr) -- the downside being that the call will be interpreted.
You could do a limited (read-only) form of this in a macro by basically checking all names in a macro against the current scope and then prepending `MyModule.X` if it is not found. I've wanted this occasionally, because it would make copy-pasting code from a module somewhat easier, for debugging purposes. On Fri, Sep 5, 2014 at 4:58 PM, Andrei <[email protected]> wrote: > In module.c in Julia sources I see "jl_set_current_module()" function. Is > it somehow exposed to Julia API? > > To give you some context, in Common Lisp (as well as some other dialects) > there are 2 separate macros for dealing with packages (analogue of modules > in Julia): > > defpackage - defines new package and switches to it > in-package - simply switches to specified package > > One great feature that these macros bring is ability to easily switch > context of execution. E.g. in REPL (code simplified): > > ;; initially working from cl-user package > cl-user> (defpackage foo (:use :common-lisp)) ;; automatically switched > to new package > foo> (defvar x 1) > X > foo> x > 1 > foo> (in-package :cl-user) > foo> x > ;; error: x not defined in :cl-user > > This is extremely helpful for both - package extension and > debugging/interactive development. E.g. we can switch to a module in > question and get all internal variables visible, play around in that > context and go back to main package without stopping REPL. > > So I'm wondering if something like this is possible in Julia at all. >
