Olical / conjure

Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile, Python and more!)
https://conjure.oli.me.uk
The Unlicense
1.79k stars 110 forks source link

Julia: evaluating functions from imported packages #617

Open theplatters opened 1 week ago

theplatters commented 1 week ago

When using Conjure with Julia and Tree-Sitter evaluating a form, when over a simple function call correctly send the function call to the repl. i.e abs(-3) => 3 evaluates correctly. When however doing the same on functions, that are called from a module, only the function definition is sent to the repl. i.e: using Pkg Pkg.activate("project") => activate (generic function with 3 methods)

Expected behavior: Evaluate the function call.

Olical commented 1 week ago

Ah! So in this cause Pkg.activate is being sent but not the actual application of it through the parens. Investigating!

Olical commented 1 week ago

While debugging this, TIL about :InspectTree, perfect for debugging tree sitter stuff! Used to be this plugin https://github.com/nvim-treesitter/playground

image

Olical commented 1 week ago

Pushed some changes to the main branch that should fix your issues. I also made it so we don't treat argument lists as valid forms, so if you eval from within the arg list now it correctly executes the function instead of returning the arg list as a tuple.

Olical commented 1 week ago

Improved it again, now if you have Foo.bar on it's own ee will evaluate and return bar. If you have parens after the end and it's actually a call_expression then the whole thing will be called. So you can have lines that look things up and things that call things and ee should "do the right thing". There's always er too if Conjure is only evaluating a part of something and you want it to do the WHOLE thing.

theplatters commented 1 week ago

Thanks for the quick fix

theplatters commented 6 days ago

Hey, I found a simmilar bug

a = 3
b = 4

(a,b) = b,a

evaluating the last line just evaluates (a,b) and not (a,b) = b,a. a,b = b,a work's fine, so this is not that terrible of a bug.

Olical commented 3 days ago

Hmm I'm looking at adding another special rule that states a tuple evaluation that's a child of an assignment should instead evaluate the whole assignment. Although what if you want to evaluate the right hand side of the assignment, just the value?

Or even if you've already evaluated the assignment and you want to evaluate the left hand side tuple to print a and b at the same time? Suddenly you won't be able to have that nuance.

Alternatively, you can use <prefix>er to evaluate the root form, this will evaluate the whole expression leaving <prefix>ee to evaluate individual parts which is how those mappings were originally designed.

In lisps it's very clear cut what counts as a full expression, in other syntaxes I think it's less clear and more up to interpretation and context.

If we had (a, b) = (1, 2) and I <prefix>ee on the right hand side, I might want that tuple to be evaluated on it's own instead of the whole expression. Although there's an argument to be made for one of the main Conjure goals: Least surprise.

Maybe a user will ALWAYS want a full assignment expression to be evaluated. I'm torn!

Olical commented 3 days ago

Oh actually, evaluating an assignment actually shows you the result which is nice.

Olical commented 3 days ago

Okay, added this rule, the user can still use visual eval or motions like ea( to evaluate something more specific. But the default behaviour is now "if you eval in an assignment, the assignment is evaluated" because it prints the results anyway as part of that operation. I was worried it would hide the results so you'd have to write specific expressions to print the results after.