[Feature suggestion] Namespaces via modules #2713
Unanswered
mgkuhn
asked this question in
Pluto development
Replies: 1 comment
-
That would be a great addition! I missed something like this quite a few times, but didn't formulate it as a consistent feature request. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When we ask students to submit homework consisting of several exercises in form of a single Pluto notebook (exported to PDF), they often end up submitting something like:
Note how they used Markdown headings to split a single notebook into separate sections, one for each exercise, but then had to (slightly awkwardly) rename common variable names, such as
x
andy
, intox1
,y1
,x2
,y2
, as both exercises share the same global namespace.Now there is a workaround for that, namely
let ... end
blocks, to placex
andy
into a local scope. However that then hinders reactive debugging and experimentation, because now all related assignments end up in a single cell, and one no longer can make intermediate values visible by simply removing the trailing semicolon.Julia has already a mechanism for switching between several namespaces for global variables: modules. I wonder if Pluto could use modules to support several namespaces within a single notebook.
At the moment, modules can't be used for that, because modules are constrained to within a single cell. So what would be needed is some sectioning or nesting mechanism that would allow modules to enclose multiple cells, to move them into their own global namespace.
This is just a vague idea right now, but one approach might be to add to Pluto a new "Section heading" cell type that contains a section title (which could also be re-used as a module name), and that at the same time starts a new module (and closes any prior module at the same nesting level). This might be encoded as something like
Such a section-heading cell (
╔s╡
) might do several things:using
expressions previously given inMain
(such that the user doesn't have to repeat them for each section)import
any previous (or even following?) modules, such that global variables from there can still be referencedThe automatic import of other modules would still allow references to variables defined in other sections, e.g., if in Exercise 2, the task was to compare with the results of Exercise 1, the student could add there
Only vaguely related: #1012, #2255, #1455, #1615
Beta Was this translation helpful? Give feedback.
All reactions