Open altavir opened 3 years ago
Idea is cool, but there are two things I don't like in proposed API:
KotlinKernelHost
interface (or extensions on this interface) which is responsible for execution itself.What do you think?
No objections against the second one. My point was it should not be a top-level function. As for the first one, they should not be two receivers of the same type, the function of the lower receiver in the stack could not be ever called and it could cause bugs. So I think that adding a new receiver with the same type should either replace the current one or cause an exception. Removal could be done by value, but it actually complicates the procedure since you need to keep that value somwhere.
The use case Consider the code here: https://github.com/AndreiKingsley/kmath-tensors-example-jupyters/blob/master/kmath_tensors_examples.ipynb. KMath extensively uses context-oriented programming so each section on the code should be encapsulated with the appropriate receiver. Usually, we just do something like
fun main() = DoubleTensorAlgebra{...}
to avoid additional clutter. In jupyter one have to wrap each cell in it which looks ugly.Additional use cases:
CoroutineScope
for the notebook to allow convenient coroutines without explicit top-level scopes (and to avoid GlobalScope).Proposed syntax
Functions are used on
Notebook
to improve discoverability and avoid accidentally calling them.Risks Broad usage of implicit (including implicit receivers) could cause a lot of confusion in a large code, so this feature should not be used in large notebooks. The receiver should be declared in the notebook explicitly so it probably should not be used in plugins.
Adding multiple receivers which export the same functions and properties could produce unexpected behavior since the resolution could depend on the order. So there should be cell magic to list currently loaded receivers.