read-eval-print-loophy

configure automatic Hy REPL imports


I've been absolutely loving the Hy REPL. However it would speed up my workflow immensely if I could have a set of default imports at startup. Clojure has a way of configuring startup imports via leiningen config. Currently I load the repl this way:

path/bin/hy --repl-output-fn=hy.contrib.hy-repr.hy-repr

Similarly is there a way I can reset all imported modules from the REPL namespace without having to restart the REPL ?


Solution

  • Update

    The environment variable HYSTARTUP can be set to the path of a Hy script to be run when the REPL starts.

    You still can't in general "reset all imported modules from the REPL namespace without having to restart the REPL", because this amounts to hunting down all references to the module objects. You can del variables holding module objects, as well as entries of sys.modules, and in some cases, this will suffice.

    Original answer

    Proper initialization scripts are not yet implemented. In the meantime, you can do things like

    hy -i '(import math re pandas)'
    

    or

    hy -i '(import [my-init-package [*]])'
    

    to run some code of your choice before starting the REPL.