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

Conjure ignores ; in Julia #416

Closed
usmcamp0811 opened this issue Sep 12, 2022 · 4 comments
Closed

Conjure ignores ; in Julia #416

usmcamp0811 opened this issue Sep 12, 2022 · 4 comments
Labels
client-julia enhancement New feature or request

Comments

@usmcamp0811
Copy link

usmcamp0811 commented Sep 12, 2022

When using Julia, Conjure seems to ignore ; placed at the end of a line. In Julia it is used to suppress the returning of the lines output. This is a problem because when you open a 15,000 line CSV into a DataFrame, Conjure kind of craps the bed and becomes really slow as it tries to print every single line.

Example code to return the problem.

using Downloads
using CSV
using DataFrames
example_csv = Downloads.download("https://raw.githubusercontent.com/JuliaAcademy/DataScience/main/programminglanguages_CSV.csv")
data = CSV.read(example_csv, DataFrame);

if you run the above in Conjure it will return the dataframe into the log. If you run it in a REPL it will not return anything (the desired result).

This is a hack to not return something

using Downloads
using CSV
using DataFrames
example_csv = Downloads.download("https://raw.githubusercontent.com/JuliaAcademy/DataScience/main/programminglanguages_CSV.csv")
# this will cause it to return the `example_csv` path instead of the `DataFrame` 
data = CSV.read(example_csv, DataFrame); example_csv

I have tested this with :ConjureEval in normal and visual modes. I've done <localleader>eb and get the same results. Pretty much I've tried it with every eval method I saw as being made public in Conjure.

@usmcamp0811
Copy link
Author

usmcamp0811 commented Nov 1, 2022

So as to add a little bit of info to this in the event I get hit by a bus or future people look back.. I spent a good bit of yesterday poking and prodding things to see what I could learn. The biggest take away I could gather is that interfacing with the Julia REPL via stdin will completely ignore all ;. The thing that will squash the out put if ended with a ; is a function built into the Julia REPL and defined around here. When we pipe or otherwise send things to julia via stdin it would seem we are not hitting the REPL at all, but rather just going straight to the compiler, hence we still get back big long arrays even when we don't want or need them.

All is not lost as mentioned elsewhere on here I looked into the RemoteREPL and its legit! I think we can use this to give comparable support to Julia as is for Clojure. Somewhere I found this shell script and I made some modifications to it (below) and it can currently take in a string argument that will 100% be sent to the remote REPL and will be processed as expected. It will then @show the like where its evaluating things.

My Lua skills are meh.. and my fennel skills are worse.. I'm going to give this a shot but don't let me stop anyone... at least not till I get an MR in... Any way that covers basic I/O that we have with the current stdio extension.

I looked at the RemoteREPL and it has complete_line, that could give completion and I think there might be more that it is capable of providing.

#!/bin/bash
#=
[[ $1 == +* ]] && juliaup_arg=$1 && shift # release channel for juliaup
exec julia ${juliaup_arg} -O0 --compile=min -q -i --startup-file=no -e 'include(popfirst!(ARGS))' "$0" "$@"
=#
let
  # Use an anonymous module to avoid polluting the Main namespace
  init_mod = Module()
  @eval init_mod begin

    using RemoteREPL, Sockets, ReplMaker

    if length(ARGS) > 1
      host = ARGS[1]
      stdio = ARGS[2]
    else 
      host = Sockets.localhost
      stdio = ARGS[1]
    end

    atreplinit() do repl
      prompt = connect_repl(host, startup_text=false, repl=repl)
      println(RemoteREPL.remote_eval(stdio))
      exit()
    end

  end

end

This bash script is just a wrapper around actual Julia code. I hadn't seen this method before but I saw it mentioned on the Julia Discourse in case anyone was wondering whats going on with it.

Example uses:

╰─± ./get_variable.sh "[rand() for i in 1:1000];"
RemoteREPL.remote_eval(args) = nothing


╰─± ./get_variable.sh "b = 45"                               
RemoteREPL.remote_eval(args) = 45


╰─± ./get_variable.sh "2b+45"                                
RemoteREPL.remote_eval(args) = 135

So the first thing I am going to do is begin hacking on the stdio code so that I can run this script and then parse the output. If I can do this we should be able to close this issue and make and work on the full implementation of the RemoteREPL in Conjure

@Olical
Copy link
Owner

Olical commented Nov 12, 2022

PR merged but we can still maybe improve the tree sitter support by including ; somehow so you don't have to use visual selection.

@Olical
Copy link
Owner

Olical commented Nov 13, 2022

Got it! Required a whole new system for overriding tree sitter selections but it works and can be used by any other client.

Hooray for reusable leverage!

Let me know if it works okay for you, looks good to me but I'm not a Julia person so I don't know what to look for to break it.

@usmcamp0811
Copy link
Author

Just tried it out and it works!

Maybe we can make you a Julia person.. go try julia --lisp :-)

@Olical Olical closed this as completed in 2ef87b5 Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client-julia enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants