-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Support :init option when creating a repl #315
Comments
|
Oh my mistake, that means it would be like this? (require ‘[promesa.core :as p])
(repl/repl
{:init #(apply require ‘[[promesa.core] :as p]
[clojure.repl :refer [doc]]
[cljs.pprint :refer [pp pprint]])}) Then the implementation should run that within a promise? |
the function can return a promise or an ordinary function and will then be chained onto the rest of the stuff here: Line 203 in b9c2631
|
That helps a lot! Last question: How should it deal with the optionality? (-> ...
(.then (if (ifn? (:init opts)) (:init opts) identity))) |
I'd say:
|
Should that let also contain a runtime check like? (when-not (ifn? init)
(js/throw (js/Error. ":init must be a function"))) |
I would say that's overkill |
@eccentric-j Maybe this would also be nice to have for the nREPL server? But I'll close the existing issue for now. |
Is your feature request related to a problem? Please describe.
When creating a repl with
(nbb.repl/repl)
it could take an :init option that evaluates forms to intern bindings within the repl.Describe the solution you'd like
A similar implementation to core repl
:init
https://insideclojure.org/2020/02/11/custom-repl/ but in Slack you mentioned wrapping it in a promise for require support.Describe alternatives you've considered
It might be possible to loop through the symbols of an existing namespace and create local defs to make a namespace available, but feels non-idiomatic, plus would likely not work with macros.
Additional context
Use case is I’m updating the nbb replit and thought it would be helpful if one could fire up the repl and instantly write something like:
Questions
What would the usage look like? Based on what was discussed, I’m picturing:
The text was updated successfully, but these errors were encountered: