There are more details here:
http://groups.google.com/group/clojure/search?group=clojure&q=reader+macro&qt_g=Search+this+group
There is a clever technique described on the wiki that allows Clojure Shebang scripts:
http://en.wikibooks.org/wiki/Clojure_Programming#Shebang_Scripting_in_Clojure
(There's a link there that points to a posting that explains how it works.)
--Steve
On Saturday, November 15, 2008, at 07:52PM, "Jeff Rose" <ros...@gmail.com> wrote:
>
>Hi, I'm finding comments talking about reader macros, but nothing about
>defining them. Does anyone know of an example for adding new read
>macros? I'd like to define a #! macro that passes over the rest of the
>line so we can use clojure scripts just as easily as a ruby script would
>be. If anyone knows another way to do this, that would be great too.
>
>Thanks,
>Jeff
A big +1! Everybody shouldn't have to write this script themselves or
copy it from the Wiki. It could require that certain environment
variables be set such as CLOJURE_HOME, CLOJURE_CP, and maybe
JLINE_HOME. The last one could go away if Clojure shipped with a JLine
.jar file.
--
R. Mark Volkmann
Object Computing, Inc.
>
> On Sun, Nov 16, 2008 at 6:59 AM, Jeff Rose <ros...@gmail.com> wrote:
>>
>> For that matter, a standard clj script
>> or executable should probably be a part of the package too.
>
> A big +1! Everybody shouldn't have to write this script themselves or
> copy it from the Wiki. It could require that certain environment
> variables be set such as CLOJURE_HOME, CLOJURE_CP, and maybe
> JLINE_HOME. The last one could go away if Clojure shipped with a JLine
> jar file.
Mine's here if you want to avoid writing one: http://github.com/dudleyf/clojure-bin
. It'll detect JLine on the classpath and use the ConsoleRunner
accordingly.
:dudley
I set up SLIME/SWANK/Clojure on my Linux system, but indentation isn't
working.
The doc says that indentation should "just work"... but nothing
happens. I tried "indent-region", "indent-sexp" and
"slime-update-indentation"
What's the trick?
Thanks
P
It looks like SWANK is sending the progn to Clojure which complains.
What did I do wrong?
Thanks
P
(progn (load "/usr/share/slime-2008-11-15/swank-loader.lisp" :verbose t)
(funcall (read-from-string "swank-loader:init")) (funcall
(read-from-string "swank:start-server") "/tmp/slime.27190"
:coding-system "iso-latin-1-unix"))
Listening for transport dt_socket at address: 8888
Clojure
user=> java.lang.Exception: Unable to resolve symbol: progn in this context
clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:1: Unable to
resolve symbol: progn in this context
at clojure.lang.Compiler.analyze(Compiler.java:3713)
at clojure.lang.Compiler.analyze(Compiler.java:3671)
at clojure.lang.Compiler.access$100(Compiler.java:37)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2634)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:3860)
at clojure.lang.Compiler.analyze(Compiler.java:3698)
at clojure.lang.Compiler.analyze(Compiler.java:3671)
at clojure.lang.Compiler.access$100(Compiler.java:37)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3384)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3231)
at clojure.lang.Compiler$FnMethod.access$1200(Compiler.java:3142)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:2766)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:3856)
at clojure.lang.Compiler.analyze(Compiler.java:3698)
at clojure.lang.Compiler.eval(Compiler.java:3889)
at clojure.lang.Repl.main(Repl.java:75)
Caused by: java.lang.Exception: Unable to resolve symbol: progn in this
context
at clojure.lang.Compiler.resolveIn(Compiler.java:4019)
at clojure.lang.Compiler.resolve(Compiler.java:3972)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:3955)
at clojure.lang.Compiler.analyze(Compiler.java:3686)
... 15 more
user=>
.emacs
(add-to-list 'load-path "/usr/share/clojure/clojure-mode")
(add-to-list 'load-path "/usr/share/slime-2008-11-15/") ; your SLIME
directory
(setq inferior-lisp-program "/usr/share/clojure/clojure") ; your Lisp system
(setq swank-clojure-binary "clojure")
(require 'clojure-auto)
(require 'swank-clojure)
(require 'slime)
(slime-setup)
I've added #! as a to-end-of-line comment, like ;
Apparently to use SLIME with Clojure, you need to install a Common Lisp.
I assumed that SLIME was written in EMACS Lisp, but apparently not. In
his Blog, Bill did say
"If you already use a CL implementation with SLIME
<http://common-lisp.net/project/slime/> and Emacs, then getting setup
with Clojure is pretty straight-forward."
http://bc.tech.coop/blog/081023.html
But I didn't realize that meant SLIME was dependent on CL.
I used CMUCL and everything works now.
Thanks
Peter
+1
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
rosejn@meld:~/projects/languages/clojure$ cat foo
#!/usr/bin/env clj
(println "Hello World!")
rosejn@meld:~/projects/languages/clojure$ chmod u+x foo
rosejn@meld:~/projects/languages/clojure$ ./foo
Hello World!
-------------------------------
Awesome. Thanks Rich.
-Jeff
I would like both the REPL and Script to be callable from the same main
(), i.e. you should just be able to call java -jar clojure.jar without
naming a class. Default behavior would be to run a script, as with
bash/perl/ruby, use a special command-line arg to run a REPL. Or
maybe imitate python, and run a REPL if there are no command-line
args. Either way is cool by me.
If I have time today, I'll cook up some code for this.
On Sun, Nov 16, 2008 at 11:40 AM, Peter Wolf <opu...@gmail.com> wrote:
>
> This is for the other NOOBs...
>
> Apparently to use SLIME with Clojure, you need to install a Common Lisp.
This is not correct. You don't need to install a Common Lisp in order
to use SLIME with Clojure.
> I assumed that SLIME was written in EMACS Lisp, but apparently not. In
> his Blog, Bill did say
>
> "If you already use a CL implementation with SLIME
> <http://common-lisp.net/project/slime/> and Emacs, then getting setup
> with Clojure is pretty straight-forward."
>
> http://bc.tech.coop/blog/081023.html
I was saying that it was easy to get started with Clojure & SLIME if
you were already using SLIME with a CL (since you would already have
SLIME installed and would already be accustomed to using it). Sorry if
you interpreted this differently.
> But I didn't realize that meant SLIME was dependent on CL.
SLIME isn't dependent on CL. The SLIME install is made up of an Emacs
Lisp component plus a SWANK component (that are written for the
underlying Lisp implementation that you are using). There are separate
SWANK components for several different CL implementations, at least
one Scheme implementation, and Clojure.
> I used CMUCL and everything works now.
SLIME works with CMUCL, but that has nothing to do with whether you
are able to get SLIME working with Clojure.
- Bill
Using the shebang line like this is not portable. See the following
post for details:
http://lists.freebsd.org/pipermail/freebsd-arch/2005-February/003525.html
To summarise the above post, on many operating systems if you ran a
script called scriptname.clj that started with the following shebang
line:
#!/usr/bin/env java -cp /sq/ext/clojure/clojure.jar clojure.lang.Script
it would be as if you had written:
$ /usr/bin/env "java -cp /sq/ext/clojure/clojure.jar
clojure.lang.Script" scriptname.clj
which would give you an error like:
/usr/bin/env: java -cp /sq/ext/clojure/clojure.jar
clojure.lang.Script: No such file or directory
I've just tried this on Linux with a 2.6 kernel and that's exactly what I got.
--
Michael Wood <esio...@gmail.com>