Closed clouds56 closed 5 years ago
Could you write more about the reason why we need ans and out for every output?
Not every time before running a function you would know the result is useful, so most of the time you would not give an name to the result in the quick prototype.
Of course you could prepend out[execution_count] = ans =
to your actual code every time, but it could be fantastic if the kernel have done it for you.
In fact, in ipython there's already _
(means ans
here) and _1
, _2
, ... (means out[1]
, out[2]
here), and original in mathematica, there's also Ans
and Out[1]
, Out[2]
.
For example, you've got a large matrix
m = Matrex.magic(1000)
and you would like to know if the matrix is reversible, you would likely to run
determinant(m)
to check if the determinant is 0, now say you would like to reverse the matrix and without knowledge, you would not likely to know that the determinant in the last execution of the matrix is useful, but never mind, we could access it in ans
Matrex.divide(adjugate(m), ans)
This could avoid lots of cost to recalculate the determinant.
Another example could be spawn
spawn(&some_heavy_function/0) # out[1]
after some execution you found something wrong and would like to kill the pid, out
would save you
Process.exit(out[1], :kill)
The only concern to me is that should we use ans
or _ans
or just __
(double underscore) as the name? And should out
be a map or bind it to multiple names out1
, out2
, etc.?
Commit has been merged as https://github.com/pprzetacznik/IElixir/commit/5772ae9beb0c94102781904230c7b3368167b992 to the master. Unfortunately, github hasn't shown this ;_; Thanks for the input!
as the ipython
_
and_1
,_2
, etc.