Closed jonahx closed 5 years ago
@jonahx J sentences in a notebook cell are feed to the J interpreter line-by-line. So the cell contents:
f=. & @ +
2 f 3
result in a value error because f has not evaluated to a definition. At the time when "2 f 3" is executed, f does not exist. Try only the sentence "f=. & @ +" in a cell. This results in a "syntax error", not in a "value error". Yes, this behaviour can be misleading because only the error message of the last line is displayed. I will investigate in that as soon as my time permits.
f=. & @ + <-- syntax error, but not displayed
f=. + <-- correct definition *1
2 f 3 <-- correct evaluation
f=. & @ + <-- syntax error, but not displayed
2 f 3 <-- correct evaluation because f from *1 is still defined
So the good news are that old definitions/variables do NOT persist.
@martin-saurer
Thanks for looking into it.
Yes, this behaviour can be misleading because only the error message of the last line is displayed. I will investigate in that as soon as my time permits.
Fwiw, I think either of these 2 options would avoid any confusion:
So the good news are that old definitions/variables do NOT persist.
What about the behavior I'm seeing in item 3 from my OP?
@jonahx The behavior of item 3 in your OP is what I tried to describe. The last “good” definition of f stays in effect until a new “good” definition is made. A “bad” definition of f (syntax error) does not overwrite or clear the last “good” definition of f.
@martin-saurer
The behavior of item 3 in your OP is what I tried to describe. The last “good” definition of f stays in effect until a new “good” definition is made. A “bad” definition of f (syntax error) does not overwrite or clear the last “good” definition of f.
I think less confusing behavior would be for a "run cell" to wipe out the previous memory and behave as if the cell you see in front of you, right now, was all that ever existed. Essentially, we want the code itself to be referentially transparent. This is how it works for python notebooks, eg.
Python also keeps variables from previous cells. Wipe out the memory for all previous cells, when running a new cell, is a bad idea.
This is best demonstrated with a simple example:
1. create some erroneous definition
The error is correct, since the definition of
f
is a syntax error.2. now create a correct definition and "run cell" again
Still working as expected, since we've re-bound
f
to a valid definition.3. now delete the correct definition and "run cell" again
The result here should be the same as in step 1, but the correct definition of
f
is still hanging around...