开发者

Multiline shebangs in Clojure?

Goal: produce a Clojure script which runs -main when run as ./script.clj.

The closest I've gotten is

#!/bin/bash
#(comment
exec clj -m `basename $0 .clj` ${1+"$@"}
exit
#)
(defn -main开发者_Python百科 [args]
   (println args))

But Clojure doesn't allow non-Lisp code inside multline comments, and Clojure doesn't have Common Lisps's #| ... |# syntax.


The syntax is obscure, but it works. From Wikibooks.

$ ./hello.clj Fred
Hello Fred!

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

(ns hello
    (:gen-class))

(defn -main
    [greetee]
    (println (str "Hello " greetee "!")))


Since Clojure CLI became available, use

#! /usr/bin/env clj

(println "Hello World!")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜