In a notebook, I can have one cell with this
let a = 10
let b = 20
and another cell with that.
let b = "Miles Davis"
let c = "Jimi Hendrix
a and c are unique across the entire notebook. So they are global, if I understand correctly. They can be used anywhere in the notebook and imported into another notebook.
On the other hand, b exists twice. Its scope is local. It cannot be called globally from anywhere in the notebook, and it cannot be imported into another notebook.
Question: Is there no way to import b into another notebook by specifying that we want the one from the first cell, or by using a cell ID?
I don’t think it is valid to have a notebook with conflicting top level variables or constants. Declarations are evaluated lazily so those two bs are in a ‘will conflict once they’re used’ state at the moment. Try creating a third cell that references b. It will reveal the conflict.
I think the solution is to keep names to local scope by enclosing the cell in braces or a function (which will shadow top level ones with the same name without a conflict). That will also make it clearer which can be exported.
I understand. That makes sense. I was just wondering whether, thanks to a cell ID, it would be possible to identify a variable unambiguously. Apparently not.
It’s valid to have notebooks with conflicting (or “non-unique”) top-level variables. The limitation is that you can’t reference those top-level variables from other cells. And imports by definition are cross-cell (cross-notebook!) references.
So in your example, you can absolutely import a and c and the ambiguous definition of b will not interfere. But there is no way to import b because it is ambiguously defined.