Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use package in Julia without importing it?

Tags:

julia

If you write it imports all bunch of methods into the current scope.

using Plots
plot(rand(5,5))

I need only one method, is it possible to write the same code but without using or importing anything, I don't want to pollute the current scope with Plots exports and don't mind to prefix it with package name every time I use it.

Plots.plot(rand(5,5))
like image 361
Alex Craft Avatar asked Dec 10 '19 17:12

Alex Craft


1 Answers

import will bring a module into scope without any of its exported names. You can still use qualified names to reference names within the imported module:

import Plots
Plots.plot(rand(5,5))

To avoid using the qualified name, you can create a binding to a new name:

const plot_from_plots = Plots.plot
like image 191
David Varela Avatar answered Oct 02 '22 21:10

David Varela