Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia support #542

Open
BeastyBlacksmith opened this issue Oct 25, 2019 · 9 comments
Open

Julia support #542

BeastyBlacksmith opened this issue Oct 25, 2019 · 9 comments

Comments

@BeastyBlacksmith
Copy link

Nice notebook!

Are there any plans to include julia?

@dondish
Copy link

dondish commented Oct 25, 2019

Wow, this totally could be implemented using https://github.com/JuliaInterop/JavaCall.jl like Python!

@BeastyBlacksmith
Copy link
Author

BeastyBlacksmith commented Oct 25, 2019

That would be awesome! That should work at least for the long term support branches of julia (1.0.x) and probably julia 1.3 once it is released.

@jeremyrsmith
Copy link
Contributor

We'd welcome a PR for this! Intending to have some rough developer documentation up soon, but the main part of adding a new language is just implementing this interface: https://github.com/polynote/polynote/blob/master/polynote-kernel/src/main/scala/polynote/kernel/interpreter/Interpreter.scala

@wizofe
Copy link

wizofe commented Mar 2, 2020

Hi! Are there any further plans for this? Could you give some more info on what is exactly needed to implement Julia as plugin?

@jeremyrsmith
Copy link
Contributor

@wizofe we don't have any immediate plans to add Julia support, but of course a PR would be welcome. It would involve creating a JNI binding for running Julia code and introspecting Julia values, and implementing the Interpreter trait.

@jeremyrsmith
Copy link
Contributor

@BeastyBlacksmith @dondish @wizofe I started playing around with making a JNA-based interface to libjulia, for the JVM->Julia part (and I guess the Julia->JVM part could be accomplished by JavaCall.jl as @dondish mentioned, though it doesn't look like a particularly nice interface at the moment).

Theoretically, I could make a plugin now that interprets Julia code. But, there's a couple of roadblocks (around how to make something like a "scope" in Julia... and then things like how autocomplete could work, and so forth), and my problem is that I don't really know anything about Julia. To get any further, I'd definitely need help from someone who knows & loves Julia – so if anybody wants to collaborate on this, let me know!

@BeastyBlacksmith
Copy link
Author

BeastyBlacksmith commented Apr 14, 2021

Julia does support the language server protocol (https://github.com/julia-vscode/LanguageServer.jl) which should get you autocompletion and stuff.

Scopes can be most easily created either by let blocks or functions, but the section of the manual is also quite good on this.

I don't know much about Java or building editors, but I'd help where I can

@jeremyrsmith
Copy link
Contributor

@BeastyBlacksmith I guess what we'd mostly need to figure out is, how cells should be "encoded" in Julia.

Every cell has to be able to use any variable from any cell that comes before it. We have different ways of accomplishing this in Scala and Python.

In Scala, everything has to be a class, so we make a class that takes every available value as a constructor parameter, and the code for the cell goes into the constructor (more or less). This also makes any values defined in that cell available as fields of the cell class. Before compiling the cell, we do an extra pass where we eliminate any available values which aren't used, in order to keep stuff sane-ish. After executing the cell, we have a convenient object with a field for each value the cell defined, so we can pull those out so that they can be used in subsequent cells.

In Python, we have a very convenient function exec(code, locals, globals) where code is the python code, and locals is a scope dictionary of "locally available things" and globals is a scope dictionary of "globally available things". This makes it really easy to control the scope of the code. Also, if we pass an empty locals dictionary to that, we can get back out whatever that python code defined by inspecting that dictionary after the code has run. Which makes it really easy to get the python declarations out so they can be used by subsequent cells.

Libjulia has a similar thing called jl_eval_string, but it doesn't take those scope dictionaries... so I can't immediately see how we could A) provide the available scope to that code, and B) extract the values that were defined by the code.

@BeastyBlacksmith
Copy link
Author

Regarding A) Assuming you treat every cell as a function you could usejl_call which accepts an array of arguments to pass state from cell to cell. As far as I understand the embedding section of the manual.

I am not sure about B), but there are a few discussions about embedding julia in the JVM on the julialang discourse and this thread is a decent summary.
I hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants