Hi,

Am 18.04.2009 um 01:16 schrieb Stephen C. Gilardi:

I have a proposal for a standard way to make a namespace "executable"
and to invoke it as a program/script.

I miss this so badly! Up to now, I always used gen-class to compile
a class with a main function to get this functionality. Since I mostly
don't do scripting in Clojure this approach worked well until yesterday.
There I needed that really badly and didn't have it....

Thoughts?

Ok. You asked for it, so I will play the devil's advocate!

Why this fixing on one somehow blessed function? When the
namespace is loaded I can call any public function directly.
Why do I need (run ...)? I don't see the value of this, since run
should probably return a numeric exit code, no? While any
other function will provide eg. a map or a seq, which is probably
much more useful.

Let me bring scsh into the discussion and show how they handle
this issue. They have a command line switch to tell the scsh driver
which function to invoke after loading the script. This could also
be done for clojure.main:

java -cp .. clojure.main -E my.ns/main my-script-defining-my-ns.clj

The script does not need to be in the Classpath. As soon as it is
loaded the namespace is available. (Which brings me to the
double book-keeping of require...)

The script could be made self-contained using hashdot:

#! /usr/bin/env hashdot
;;.hashdot.main = clojure.main
;;.hashdot.args.pre = -E my-ns/main

(ns my.ns)

(defn main
  [& args]
  ...)

./my-script-defining-my-ns.clj

With this approach I can also choose different entry points for
different invokations of the same script. Although I'm not sure this
is an interesting feature.

Just some thoughts to a look a different approach.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to