-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Load a script file in the repl without some things getting evaluated, but when the script is run they should be evaluated #4
Comments
@PEZ I think it's good to ask ourselves: how can we support this without adding options. Are there any existing solutions around that Clojure users are already familiar with? Why is there no such a thing in Clojure proper? Etc. |
E.g. one solution that already just works in user space is:
|
Yes, there are probably much better alternatives. I am not really floating solution ideas here, more the need. The ”idea”, insofar there is one, was inspired by how I use Babashka. One solution would be to do the same as with Babashka. I.e. set
I think it is because it was not designed as a scripting language. |
I solved my use case for now like so: (ns ignore-form
(:require ["vscode" :as vsode]
[promesa.core :as p]
[z-joylib.vscode-utils :as vsu]))
(defonce run-main? true)
(comment
;; Loading this in the REPL w/o evaluating `main`:
(defonce run-main? false) ; <- First evaluate this
(ns-unmap *ns* 'run-main?) ; <- Evaluate this when you are done
; or want to test-run the script
)
(defn main []
(p/let [editor ^js vscode/window.activeTextEditor
original-selection (vsu/current-selection)
_ (vscode/commands.executeCommand "paredit.backwardUpSexp")
insert-position (.-active (vsu/current-selection))]
(aset editor "selection" original-selection)
(p/do! (vsu/insert-text!+ "#_" editor insert-position))))
(when run-main?
(main))
(comment
(main)
) |
Depending on how the nREPL implementation works, that might already be true. For nbb there is a similar issue: babashka/nbb#95 The way it's phased there is "detect the invoked script", I think that might be a better way to describe the problem. The solution there looks as follows:
which says: is the file that's currently being executed, the same as where one of the functions in this namespace is defined? I don't think |
First thing I tried. 😄 Didn't work. Could be that I didn't check it properly. Now that I try it I see that I have an error:
|
@PEZ It looks like you copy pasted from markdown ;) |
Please elaborate, I want to understand the joke. 😄 |
I see |
Follow up on comments on #18: Hmm... So not for this PR, but thinking about how to solve #4: In babashska I do things like:
Where the I like that pattern (think I picked it up from the Babashka book). What would a Joyride equivalent be? |
I think that would be a function: |
Awesome. You have suggested that elsewhere. Now I understand it. 😄 |
I want to be able to load a script file in the repl without some things getting evaluated, and have those evaluated if the script is being run.
Something like:
And I'd like to take a stab at this. 😄
The text was updated successfully, but these errors were encountered: