I have recently started learning Clojure and was wondering if there is a standard way of executing a simple .clj file.
I have installed Leiningen and created my first project called my-stuff using lein new app my-stuff.
To run my-stuff.core, I started with lein run:
user>lein run
Hello, World!
Next, I tried lein repl, followed by:
user=> (require 'my-stuff.core)
nil
user=> (my-stuff.core/-main)
Hello, World!
nil
I also used lein repl to do some basic evaluations:
user=> (defn sum [x y] (+ x y))
#'user/sum
user=> (sum 1 2)
3
I tried to define this function within my-stuff.core:
(ns my-stuff.core ((:gen-class))
(defn sum [x y] (+ x y))
(defn -main
[& args]
(sum [1 2]))
I get the following error: clojure.lang.ArityException: Wrong number of args (1) passed to: my-stuff.core/sum
I apologize if this is a stupid question, but how would I correctly define this function within core.clj? Does it make more sense to define it in a separate file and reference it from the core.clj file?
Thank you.
Update
If the function was defined in another .clj Clojure file, what is the correct way to declare the namespace to be able to run the code from the project my-stuff?