Modulinos: Difference between revisions

Content added Content deleted
(Perl, Python, Ruby: stop exporting a function named 'main'.)
(Added Clojure (whew!))
Line 124: Line 124:
(display (format "Test: The meaning of life is ~a\n" (meaning-of-life)))
(display (format "Test: The meaning of life is ~a\n" (meaning-of-life)))
(exit))</lang>
(exit))</lang>

=={{header|Clojure}}==
Clojure has a function -main which will run in only three cases.

1 - clj is passed the flag -m <class>

<lang sh>$ clj -m scriptedmain
Main: The meaning of life is 42</lang>

2 - A shebang forces -m

<lang sh>$ ./scriptedmain.clj
Main: The meaning of life is 42</lang>

3 - The compiled class is run.

<lang sh>$ java -cp ~/Library/Clojure/lib/clojure.jar:. scriptedmain
Main: The meaning of life is 42</lang>

scriptedmain.clj

<lang lisp>":";exec clj -m `basename $0 .clj` ${1+"$@"}
":";exit

(ns scriptedmain
(:gen-class))

(defn meaning-of-life [] 42)

(defn -main [& args]
(println "Main: The meaning of life is" (meaning-of-life)))</lang>

test.clj

<lang lisp>":";exec clj -m `basename $0 .clj` ${1+"$@"}
":";exit

(ns test
(:gen-class))

(load "scriptedmain")

(defn -main [& args]
(println "Test: The meaning of life is" (scriptedmain/meaning-of-life)))</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==