This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-25
Channels
- # 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)
I can try šø
Unless you've already gone @myles ?
Hi @seancorfield, thanks, if youāre still around, this is my question:
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ā?
Do you have (set-env! :source-paths #{"src"})
to add src
to the classpath?
I'm just setting up a test environment to make sure I can match yours
You don't need to AOT the Clojure code to just run it.
You only need to AOT it if you're planning to make a JAR to run separately.
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...
then you can (require 'hello)
and then (hello/-main)
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.
So you work with a form at a time, instead of a whole program.
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.
So there are lots of options.
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.
Does that help?
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
What editor are you using?
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
(ns hello
(:gen-class))
(defn -main [& args]
(println "hello world"))
then the following command would build you a simple JAR you can run standalone:boot -d org.clojure/clojure -r src pom -p hello -v 0.1.0 aot -n hello uber jar -m hello target
Like this:
> java -jar target\project.jar
hello world
@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
@richiardiandrea: the clifn
macro isn't hygienic, that binding is created there
oh, gotcha, so it is not actually a rebindable global?