Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change REPL module/namespace in Julia

I'm looking for a way to "enter" a module in the REPL, so that I can access all symbols without qualification (not just the exported ones), and any function (re)defined at the REPL gets in the specified module. (Basically this is the functionality of Common Lisp's in-package macro.)

This would be useful in a REPL-oriented workflow, as I would be able to write the same code in the REPL as in the module I am developing.

The manual recommends a workflow where I qualify everything, but that seems annoying.

like image 781
vukung Avatar asked Aug 03 '16 22:08

vukung


3 Answers

I started a package called REPLMods.jl for this a while back. It should probably be polished up, but I haven't had the time.

I spoke to core Julia members and there was interest in getting it merged into base once things were clean, but again, no time!

like image 99
spencerlyon2 Avatar answered Sep 30 '22 18:09

spencerlyon2


I know this isn't quite what you're asking, but just in case the 'obvious' had not occured to you (or future visitors to the question), assuming you loaded a module with an annoyingly cumbersome name, e.g.

import LaTeXStrings

and you don't want to have to type LaTeXStrings all the time just to explore its accessibles, i.e.

LaTeXStrings.[TAB]

you can just assign the imported module as a whole to another variable, i.e.

const l = LaTeXStrings

I'm sure in the absence of a more appropriate built-in solution, at least typing l.[TAB] as opposed to LaTeXStrings.[TAB]is a lot more tolerable :)

(I find it odd, in fact, that julia doesn't seem to support the import LaTeXStrings as l syntax ...)

like image 39
Tasos Papastylianou Avatar answered Sep 30 '22 18:09

Tasos Papastylianou


It's 2020, I'm using Julia 1.4, and was unable to get REPLMods.jl to work. I think the following seem good enough for the time being:

  • ExportAll.jl - see Exporting all symbols in Julia for a discussion (just that one shouldn't ExportAll to replace normal export)
  • and Revise.jl
like image 21
digikar Avatar answered Sep 30 '22 17:09

digikar