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

use of rewrite-clj breaks REPL #1188

Closed
UnwarySage opened this issue May 28, 2021 · 3 comments
Closed

use of rewrite-clj breaks REPL #1188

UnwarySage opened this issue May 28, 2021 · 3 comments

Comments

@UnwarySage
Copy link

UnwarySage commented May 28, 2021

I discovered that trying to follow the rewrite-clj tutorial breaks my REPL, and I was able to reproduce it on another computer.

Steps to reproduce.
lein new a project.
add a dependency on rewrite clj to the project.clj. I used [rewrite-clj "1.0.644-alpha"]
lein deps.
launch calva REPL, with the leiningen option.
(require '[rewrite-clj.zip :as z]) in the REPL, and then follow it with z/of-string.

Now try to define a variable, or much of anything. def seems return it's last argument instead, I can't (def some-string "It's a string, Jim") and then eval some-string without it erroring about some-string not being defined.

I file this bug here, cause the same steps behave as expected in the lein repl.

@bpringe
Copy link
Member

bpringe commented May 28, 2021

Thanks for reporting. Unfortunately, I cannot reproduce this issue. I created a new project with lein new and added the same version of rewrite-clj. I evaluated the following forms, and then evaluated x and everything worked as expected.

(require '[rewrite-clj.zip :as z])
(z/of-string "[1 2]")
(def x 1)

Could it be something about the argument you're passing to z/of-string? I'm assuming when you said "then follow it with z/of-string" you meant a call to that function.

@UnwarySage
Copy link
Author

UnwarySage commented May 29, 2021

I believe this was a false alarm.
I have two different setups on the computers I tested this on, and so don't haven't built up good msucle memory. I believe I accidentally invoked evaluation of current form, IE the last one written, instead of the form as a whole. I was then focussed enough on replicating it that I did so, perfectly on the more familiar computer.

In short, ctrl+enter versus alt+enter. This feels more like a UX issue, perhaps a momentary highlight of the form evaluated, or disabling that shortcut in the REPL?

Or chalk this one up to user error, either works.

@bpringe
Copy link
Member

bpringe commented May 29, 2021

Oh I see.

perhaps a momentary highlight of the form evaluated, or disabling that shortcut in the REPL?

If you evaluate forms from a source file you'll see the form that was evaluated highlighted. I recommend using rich comments over evaluating things at the prompt in the output window, such as is mentioned here: https://calva.io/try-first/

I do see what you mean though about it being potentially confusing for newcomers if the current form evaluation is used. In this example below, if I evaluate hello using the current form evaluation command, the end result looks like this, with nothing indicating that only hello was evaluated and not the whole form.

clj꞉core꞉> 
(def hello "world")
"world"

We have multiple options here that I see:

  1. Disable the "eval current form" command in the output window so that it's always the whole outer form that gets evaluated, which makes the output always make sense when reading it after evaluation.
  2. Highlight the form that was evaluated in the output window. (I don't think this is the wise choice because decorations like that are temporary, and we're right back at the problem above if it's read later after decorations are cleared.)
  3. If the form evaluated was not the whole form, print what was evaluated, then its result. I think this would also look odd/confusing because you could have something like this, if hello were the form evaluated:
    clj꞉core꞉> 
    (def hello "world")
    hello
    "world"

I think the best decision is either number 1 or we change nothing. I'll close this now, but I do want to know @PEZ's thoughts on the above. If a change is deemed appropriate we'll create a new issue for it.

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

2 participants