Modulinos: Difference between revisions

Content added Content deleted
(Added Mozart/Oz)
(More idiomatic, better use of Leiningen)
Line 186:
 
=={{header|Clojure}}==
Uses [https://github.com/kumarshantanu/lein-exec lein-exec].
Uses library/idiom [http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started clj]
 
scriptedmain.clj:
Clojure has a function -main which will run in only four cases.
<lang lispclojure>":";exec cljlein -m `basename $0 .clj`exec $0 ${1+"$@"}
 
# clj is passed the flag -m &lt;class&gt;. <lang sh>$ clj -m scriptedmain
Main: The meaning of life is 42
$ clj -m test
Test: The meaning of life is 42</lang>
# A shebang forces -m &lt;class&gt;. <lang sh>$ ./scriptedmain.clj
Main: The meaning of life is 42
$ ./test.clj
Test: The meaning of life is 42</lang>
# The compiled class is run. <lang sh>$ java -cp ~/Library/Clojure/lib/clojure.jar:. scriptedmain
Main: The meaning of life is 42
$ java -cp ~/Library/Clojure/lib/clojure.jar:. test
Test: The meaning of life is 42</lang>
# -main is explicitly called. <lang sh>
$ clj
user=> (load-file "scriptedmain.clj")
user=> (scriptedmain/-main)
Main: The meaning of life is 42
nil</lang>
 
scriptedmain.clj
 
<lang lisp>":";exec clj -m `basename $0 .clj` $0 ${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>
 
(when (.contains (first *command-line-args*) *source-path*)
test.clj
(apply -main (rest *command-line-args*)))</lang>
 
$ ./test.clj:
<lang lispclojure>":";exec cljlein -m `basename $0 .clj`exec $0 ${1+"$@"}
":";exit
 
(ns test
(:gen-class))
 
(load-string (slurp "scriptedmain.clj"))
 
(defn -main [& args]
(println "Test: The meaning of life is" (scriptedmain/meaning-of-life)))</lang>
 
(when (.contains (first *command-line-args*) *source-path*)
(apply -main (rest *command-line-args*)))</lang>
 
=={{header|Common Lisp}}==