This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # aatree (3)
- # admin-announcements (14)
- # aws (2)
- # beginners (23)
- # boot (58)
- # braid-chat (15)
- # cider (8)
- # clara (5)
- # cljs-dev (1)
- # cljsrn (38)
- # clojure (82)
- # clojure-china (2)
- # clojure-czech (16)
- # clojure-dev (11)
- # clojure-finland (1)
- # clojure-ireland (6)
- # clojure-japan (3)
- # clojure-portugal (1)
- # clojure-russia (152)
- # clojure-sg (7)
- # clojurebridge (3)
- # clojurescript (86)
- # code-reviews (3)
- # core-matrix (4)
- # cursive (25)
- # data-science (1)
- # datascript (2)
- # datavis (98)
- # datomic (21)
- # dirac (97)
- # emacs (1)
- # hoplon (1)
- # jobs (2)
- # ldnclj (21)
- # off-topic (3)
- # om (204)
- # pedestal (3)
- # proton (12)
- # reagent (125)
- # ring-swagger (9)
- # slackpocalypse (1)
- # spacemacs (1)
- # vim (1)
- # yada (19)
Given a dir with
src/hello.clj in it, and that file has
(ns hello) (defn -main [& args] (println "hello world”))
is there a boot invocation I can make from the repl that will build namespace in such a way it can be invoked from the command line and print “hello world”?
Well, you asked about the REPL... so ... do you want to run this from the REPL or from the shell?
but the project I’m planning on working on, will use it’s own readline based repl itself
(I’m planning to go through: https://github.com/kanaka/mal/blob/master/process/guide.md)
Well, you can just say
boot -s src repl and you've got a REPL with that
src folder on your source paths...
So I guess I’m trying to come up with a workflow where I provide a file that has a
main fn, and it gets compiled then evaluated
Well, a more common workflow with Clojure is to work in an editor, connected to a REPL, where you write code and evaluate it in the connected REPL as you go.
But you can
(require 'hello :reload-all) to fully reload your code from disk and recompile it in the REPL
You could always create a
build.boot file containing a
run task to call your main function... or you could build a full "uber JAR" (containing Clojure and all your dependencies and your program) and just run that via
java -jar from the command line.
If your program implements its own REPL, then when you run it in the Clojure REPL, it'll still work as expected, running and reading/evaluating input until it "ends" and then you'll be back in the Clojure REPL.
But that's really why it's easier to develop it from the bottom up via the (Clojure) REPL one function at a time, until you're ready to write and test the top-level loop.
If you want to see some examples of how to run a
-main function or just evaluate some code via the command line, take a look at the discussion in this ticket https://github.com/boot-clj/boot/issues/374
I'd definitely recommend keeping a
boot -s src repl open and testing code in that as you write it.
So edit code, save. Switch to REPL, require/reload code, invoke the function you're working on. Rinse, repeat.
With REPL integration you'll optimize that to edit code, evaluate it, edit code, evaluate it (and saving it occasionally).
BTW, @myles in case this helps, if your
-main namespace has
:gen-class like this
then the following command would build you a simple JAR you can run standalone:
(ns hello (:gen-class)) (defn -main [& args] (println "hello world"))
boot -d org.clojure/clojure -r src pom -p hello -v 0.1.0 aot -n hello uber jar -m hello target
@myles boot also supports shebang scripts, i.e. scripts that can be invoked just like any other program (at least on Linux). Maybe that is what you're looking for? https://github.com/boot-clj/boot/wiki/Scripts
@myles: you could also write a boot task that just runs the main method, something like:
(deftask run-main  (require 'hello) ((resolve 'hello/-main)))
Hello guys, I am working on a boot issue and would like to ask where is
*opts* defined...I can't find it