On Nov 26, 5:13 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> On Nov 24, 2008, at 11:57 AM, Stephen C. Gilardi wrote:
>
> > I've uploaded a patch along those lines:
> > ant-compile-main.patch,http://tinyurl.com/5azp3u
> > based on our recent work on this. This includes Compile.java,
> > main.clj, and modifies build.xml.
>
> I've updated this to reflect several of the comments in this thread,
> revived some behavior form Script.java (loading code from classpath)
> and included some new ideas to discuss and critique. Thanks very much
> for the discussion so far!
>
> Here's the new patch:
>
> http://tinyurl.com/6rnw9q
>
> (this does not yet include Perry's recent change to Compile.java or
> his compile script)
>
> Here's the new usage info for clojure.jar (from clojure.main):
>
> % java -jar clojure.jar --help
> Usage: java -jar clojure.jar [option*] [arg*]
>
> With no options or args, runs an interactive Read-Eval-Print Loop
>
> init options:
>
> -i, --init path Load a file or resource
> -e, --eval expr Evaluate an expression and print its value if non-
> nil
>
> main options:
>
> -r, --repl Run a repl
> path Run a script from from a file or resource
> - Run a script from standard input
> -h, -?, --help Print this help message and exit
>
> operation:
>
> - Establishes thread-local bindings for commonly set!-able vars
> - Enters the user namespace
> - Binds *command-line-args* to a seq of strings containing command
> line
> args that appear after any main option
> - Runs all init options in order
> - Runs a repl or script if requested
>
> The init options may be repeated and mixed freely, but must appear
> before
> any main option. The appearance of any eval option before running a
> repl
> suppresses the usual repl greeting message: "Clojure".
>
> Paths may be absolute or relative in the filesystem or relative to
> classpath. Classpath-relative paths have prefix of @ or @/
> %
>
> -------------------------------------
>
> Some examples:
>
> % java -jar clojure.jar -i @clojure/main.clj
>
> loads an init file from classpath (no output, but demonstrating @)
>
> % java -jar clojure.jar -e "(+ 3 4)"
> 7
> when eval returns non-nil, we println it
>
> % java -jar clojure.jar -e "(println (+ 3 4))"
> 7
> when eval returns nil, we don't print the nil (interpreting it as
> "nothing")
>
> % java -jar clojure.jar -e '"Welcome to Clojure"' -r
> Welcome to Clojure
> user=>
>
> -e before a repl suppresses the normal repl greeting
>
> % java -jar clojure.jar -r 1 2 3
> Clojure
> user=> *command-line-args*
> (1 2 3)
> user=>
>
> everything after a "main" option (repl or script name) is an arg to
> the repl or script.
>
> % echo "(println \"hi\" *command-line-args*)" > pete-best.clj
> % java -jar clojure.jar pete-best.clj 1 2 3
> hi (1 2 3)
>
> run file as a main script with args, no repl, runs and exits
>
> % java -jar clojure.jar -i pete-best.clj -r 1 2 3
> Clojure
> hi (1 2 3)
> user=> *command-line-args*
> (1 2 3)
> user=>
>
> run as an init file and request a repl, note that both the init file
> and the repl can see the args
> init files do not suppress the "Clojure" greeting.
>
> Now all the init options (eval and init) are gathered up and executed
> after the main repl or script starts--in the context of repl bindings,
> in the user namespace, with *command-line-args* bound and set!-able.
> If there is no main script or repl specified, only the init options
> run in a similar context, then clojure.main exits.
>
> Please check out the implementation of main.clj as well as the behavior.
>
> clojure.main.repl now has hooks for all of its key operations. It has
> a new "init" hook which is no-op by default but is used by the main
> repl to run the "init" options. By binding Clojure's input, output,
> and error streams (*in* *out* and *err*) and/or overriding some of the
> repl's hooks with custom implementations, one can run a repl anywhere--
> with one important case being over a socket connection.
>
> Feedback welcome.
>
Thanks for all your hard work on this Steve et al. Patch applied (SVN
1127).
Let's all shake this out so it's in good shape for Clojure 1.0.
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---