Re: reader macros

2008-11-16 Thread Meikel Brandmeyer

Hi,

Am 16.11.2008 um 04:37 schrieb James Reeves:

As far as I'm aware, Clojure doesn't support user reader macros.
There's a section in clojure.org/lisps that mentions that the read
table is not available to user programs.


Yes. Rich doesn't want to include user defined reader macros,
until there is a solution on how to avoid clashes. Similar as
Namespaces for functions. Two libraries define a Var x, but
they are in their namespaces, foo/x and bar/x, so there is no
conflict. I don't know whether #your/! and #my/! still qualify
as reader macros

Sincerely
Meikel




smime.p7s
Description: S/MIME cryptographic signature


recur in catch and finally?

2008-11-16 Thread Meikel Brandmeyer

Hi,

I tried the following code, which is a valid loop, IMHO, since it
doesn't leave the catch clause.

(try
  :xxx
  (catch Exception e
(loop [x e]
  (if (nil? (.getCause x))
x
(recur (.getCause x))

However I get:

java.lang.UnsupportedOperationException: Cannot recur from catch/ 
finally (NO_SOURCE_FILE:1)


Is this intended?

Sincerely
Meikel




smime.p7s
Description: S/MIME cryptographic signature


Re: offtopic - where are you come from? (poll)

2008-11-16 Thread Chanwoo Yoo

Seoul, South Korea, which LG and Samsung are belongs to (I know there
is few who knows where South Korea is. ^_^; It is placed between China
and Japan.)

On 10월22일, 오후10시07분, perdalum <[EMAIL PROTECTED]> wrote:
> Aarhus, Denmark
>
> On 17 Okt., 11:27, "Rastislav Kassak" <[EMAIL PROTECTED]> wrote:
>
> > Hello Clojurians,
>
> > I think after 1st year of Clojure life it's good to check how far has
> > Clojure spread all over the world.
>
> > So wherever are you come from, be proud and say it.
>
> > I'm from Slovakia. :)
>
> > RK
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Testing for lists, vectors, ...

2008-11-16 Thread Konrad Hinsen

On 15.11.2008, at 23:29, Stephen C. Gilardi wrote:

>> But there is no islist?, nor anything that looks equivalent. So how
>> do I test if form is a list? Or a vector? Or a map? For processing
>> general forms, I'd need to handle all of these, right? Or is there a
>> simpler way to do it?
>
> You can use list? vector? and map?.

Ahh, thanks. That gives:

(defn replace-syms
[sym-map expr]
(let [replace #(replace-syms sym-map %)]
   (cond (contains? sym-map expr) (get sym-map expr)
(list? expr) (map #(replace-syms sym-map %) expr)
(vector? expr) (into [] (map replace expr))
(map? expr) (into {} (map replace (seq expr)))
(set? expr) (set (map replace expr))
true expr)))

which seems to work just fine.

> To find all predicates that clojure defines, you can do this search:
>
> user=>(find-doc "[?]")

Thanks even more, that's a real life-saver!

Konrad.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Looking for the inverse of slurp

2008-11-16 Thread Ethan Herdrick

Has the inverse of slurp been added to the core libraries yet?  Like this:

(spit "Some text" "/foo.txt")

to make a file called 'foo.txt' containing "Some text".

By the way, it appears that Clojure (or Java) doesn't recognize ~, as
in (slurp "~/foo.txt").  True?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Testing for lists, vectors, ...

2008-11-16 Thread Stefan Rusek

lists, vecotrs, and hashes all have an empty() method, so

(defn clone-coll
  ([coll clone-item] (clone-item (seq coll) coll clone-item))
  ([seq coll clone-item]
(if (not seq)
  (.empty coll)
  (cons (clone-item (first seq)) (clone-coll (rest seq) coll clone-
item))
)
  )
)

will clone your collection and in if you pass your replacement
function, as clone-item, youc can replace the symbol.

On Nov 15, 11:15 pm, Konrad Hinsen <[EMAIL PROTECTED]> wrote:
> I am trying to write a function (for use in a macro) that replaces a  
> given keyword in a form by a given symbol, i.e.
>
> (replace-symbol :foo :bar form)
>
> should return the form with all occurences of :foo replaced by :bar.  
> This turned out to be surprisingly difficult. I started out like this:
>
> (defn replace-symbol [original replacement form]
>     (if (= form original)
>         replacement
>         (if (islist? form) ...)))
>
> But there is no islist?, nor anything that looks equivalent. So how  
> do I test if form is a list? Or a vector? Or a map? For processing  
> general forms, I'd need to handle all of these, right? Or is there a  
> simpler way to do it?
>
> Konrad.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: reader macros

2008-11-16 Thread Jeff Rose

Thanks for responding.  I had already seen the shebang script hack on 
the wiki, and although impressive I don't think it's a solution.  It's 
shocking to me that someone who is into lisp would even think of getting 
rid of read macros though.  For sure, there is a potential for abuse, 
but I don't think it actually happens much.  The tone set forth by the 
built-in libraries will probably have more to do than anything with 
these types of policies.  I've never experienced the pain from this, so 
maybe I'm just lucky and/or naive, but I always considered read macros 
one of the primary reasons that lisp is such a wonderful place to 
explore language ideas.

Anyways, I don't want to get into a debate for now.  In the meantime how 
about defining #! to read through until the end of the line?  Hell, it 
could even be restricted to the first line of the first file.  This 
change shouldn't effect anything else, but it will make clojure programs 
as easily runnable as any other script, which should really be a must 
have for a new language on the scene.  People coming to lisp, say from 
Ruby, Python or Pearl, already have to rewire their brains a bit, and 
making them substitute this garbage:

  #^:shebang '[
exec java -cp "$HOME/src/clj/clojure/clojure.jar" clojure.lang.Script 
"$0" -- "$@"

for this:

#!/usr/bin/env clj

makes it seem like a big hack.  For that matter, a standard clj script 
or executable should probably be a part of the package too.  How about 
it?  For the children.  Oh, and if the read table is getting modified, I 
vote for Ruby like string evaluation too :-)

Cheers,
Jeff

Stephen Gilardi wrote:
> Clojure does not currently allow programs to define new reader macros. That 
> is unlikely to change.
> 
> 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" <[EMAIL PROTECTED]> 
> 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
> 
> 
> > 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-16 Thread stefano


Romano d' Ezzelino, Italy

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Improved exception reporting

2008-11-16 Thread Rich Hickey



On Nov 14, 3:50 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> On Nov 14, 2008, at 3:11 PM, Howard Lewis Ship wrote:
>
> > The point is, an exception that said something like:
>
> > "Expected java.lang.Comparable but received :king" would have helped
> > me unravel this much, much easier!
>
> I agree. Clojure should give all the information it can about the
> object(s) involved in the failure. There are other places where the
> class of the object is given, but not its string representation. Any
> juicy info that's easily available should be made part of the
> exception message.

I'm certainly interested in improving the error reporting, but in this
partiicular case:

 java.lang.ClassCastException: clojure.lang.LazyCons

is my all-time pet-peeve exception message, and it comes from the JVM.
Why on earth they didn't report the types of both what you had and
what you were trying to cast to is completely baffling and can only be
described as a bug, which seems to be fixed in JDK 6, which reports
"XXX cannot be cast to YYY".

For every library and every app to have to wrap every cast in a try
block simply in order to get this message to say what it ought to is
not productive, IMO.

One issue with trying to capture string representations is that they
can be arbitrarily long.

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
-~--~~~~--~~--~--~---



Re: reader macros

2008-11-16 Thread Mark Volkmann

On Sun, Nov 16, 2008 at 6:59 AM, Jeff Rose <[EMAIL PROTECTED]> 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.

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: reader macros

2008-11-16 Thread Rich Hickey



On Nov 16, 7:59 am, Jeff Rose <[EMAIL PROTECTED]> wrote:
> Thanks for responding.  I had already seen the shebang script hack on
> the wiki, and although impressive I don't think it's a solution.  It's
> shocking to me that someone who is into lisp would even think of getting
> rid of read macros though.  For sure, there is a potential for abuse,
> but I don't think it actually happens much.  The tone set forth by the
> built-in libraries will probably have more to do than anything with
> these types of policies.  I've never experienced the pain from this, so
> maybe I'm just lucky and/or naive, but I always considered read macros
> one of the primary reasons that lisp is such a wonderful place to
> explore language ideas.
>
> Anyways, I don't want to get into a debate for now.  In the meantime how
> about defining #! to read through until the end of the line?  Hell, it
> could even be restricted to the first line of the first file.  This
> change shouldn't effect anything else, but it will make clojure programs
> as easily runnable as any other script, which should really be a must
> have for a new language on the scene.  People coming to lisp, say from
> Ruby, Python or Pearl, already have to rewire their brains a bit, and
> making them substitute this garbage:
>
>   #^:shebang '[
> exec java -cp "$HOME/src/clj/clojure/clojure.jar" clojure.lang.Script
> "$0" -- "$@"
>
> for this:
>
> #!/usr/bin/env clj
>
> makes it seem like a big hack.  For that matter, a standard clj script
> or executable should probably be a part of the package too.  How about
> it?  For the children.  Oh, and if the read table is getting modified, I
> vote for Ruby like string evaluation too :-)
>
> Cheers,
> Jeff
>
> Stephen Gilardi wrote:
> > Clojure does not currently allow programs to define new reader macros. That 
> > is unlikely to change.
>
> > There are more details here:
>
> >http://groups.google.com/group/clojure/search?group=clojure&q=reader+...
>
> > There is a clever technique described on the wiki that allows Clojure 
> > Shebang scripts:
>
> >http://en.wikibooks.org/wiki/Clojure_Programming#Shebang_Scripting_in...
>
> > (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" <[EMAIL PROTECTED]> 
> > 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.
>

I've added #! as a to-end-of-line comment, like ;


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
-~--~~~~--~~--~--~---



Re: Looking for the inverse of slurp

2008-11-16 Thread Stuart Halloway

Hi Ethan

spit is in Clojure-contrib. I wouldn't expect Clojure to support OS- 
specific idioms like ~, because Java doesn't.

Stuart

> Has the inverse of slurp been added to the core libraries yet?  Like  
> this:
>
> (spit "Some text" "/foo.txt")
>
> to make a file called 'foo.txt' containing "Some text".
>
> By the way, it appears that Clojure (or Java) doesn't recognize ~, as
> in (slurp "~/foo.txt").  True?
>
> -~--~~~~--~~--~--~---
>


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-16 Thread mehrheit

Vilnius, Lithuania here.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Problem with loading, classpath, svn 1106

2008-11-16 Thread Josip Gracin

Hi!

I'm getting exception
"Could not locate Clojure resource on classpath" and I don't
understand why.  From the stack trace it seems like it's trying to
load stuff according to the old library scheme, i.e. config/
config.clj.  Here's the info:

Clojure svn 1106.

Main jar file contains:
com/ingemark/b2b/monitorws/service.clj
com/ingemark/b2b/monitorws/config.clj

In MANIFEST.MF, starting class is clojure.lang.Script.
Starting it with java -jar ... @/com/ingemark/b2b/monitorws/
service.clj

service.clj starts with:
(ns com.ingemark.b2b.monitorws.service
  (:use (com.ingemark.b2b.monitorws [config :as config]))
  (:import (com.sun.net.httpserver HttpServer HttpHandler
HttpExchange)
   (java.net InetSocketAddress)
   (java.io File FileOutputStream)))


Exception in thread "main" java.io.FileNotFoundException: Could not
locate Clojure resource on classpath: com/ingemark/b2b/monitorws/
config/config.clj
at clojure.lang.RT.loadResourceScript(RT.java:361)
at clojure.lang.RT.loadResourceScript(RT.java:343)
at clojure.lang.RT.loadResourceScript(RT.java:335)
at clojure.load_resources__1738.doInvoke(boot.clj:3199)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.load_one__1701.invoke(boot.clj:3048)
at clojure.load_lib__1721.doInvoke(boot.clj:3085)
at clojure.lang.RestFn.applyTo(RestFn.java:147)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:443)
at clojure.load_libs__1725.doInvoke(boot.clj:3115)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:443)
at clojure.require__1729.doInvoke(boot.clj:3171)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.eval__2228.invoke(service.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:3847)
at clojure.lang.Compiler.load(Compiler.java:4136)
at clojure.lang.RT.loadResourceScript(RT.java:356)
at clojure.lang.RT.loadResourceScript(RT.java:343)
at clojure.lang.RT.loadResourceScript(RT.java:335)
at clojure.lang.Script.main(Script.java:60)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Problem with loading, classpath, svn 1106

2008-11-16 Thread Josip Gracin

Please disregard!  It seems I've had an older version of Clojure in
classpath.  [EMAIL PROTECTED]

Sorry for the noise.

On Nov 16, 4:24 pm, Josip Gracin <[EMAIL PROTECTED]> wrote:
> I'm getting exception
> "Could not locate Clojure resource on classpath" and I don't

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



A clojure executable (was: Re: reader macros)

2008-11-16 Thread Dudley Flanders


On Nov 16, 2008, at 7:45 AM, Mark Volkmann wrote:

>
> On Sun, Nov 16, 2008 at 6:59 AM, Jeff Rose <[EMAIL PROTECTED]> 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

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Stupid Newbie Question-- Auto Indenting in SLIME

2008-11-16 Thread Peter Wolf

Hello, I'm feeling dumb...

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


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Stupid Newbie Question-- Auto Indenting in SLIME

2008-11-16 Thread Peter Wolf

OK, I think I found the problem.  When I start SLIME I get this...  See 
below for my .emacs

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: 
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)


Peter Wolf wrote:
> Hello, I'm feeling dumb...
>
> 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
>
>


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Filter repeats

2008-11-16 Thread npt11tpn


Hi guys,
This is my first post to the group, but have been following the
discussions for almost a year. Many thanks to Rich Hickey for creating
a fantastic future-proof language which is a pleasure to use and to
the great community!
The following function (as part of a chemistry-related application)
filters the elements of a sequence that a repeated a specified number
of times. Wondering if the function could be simplified and written
without the reference (newseq).
Thanks a lot!
Nik

(defn filter-repeats [seq n]
  "Returns a vector of the elements of a sequence that are repeated n
times"
  (let [newseq (ref [])]
(doseq [u (set seq)]
  (when (= (count (filter #(= % u) seq)) n)
(dosync (commute newseq conj u
@newseq))

Usage e.g.
(filter-repeats '(2 3 1 4 2 2 4 3 5 ) 2)
[3 4]


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Filter repeats

2008-11-16 Thread Craig Andera

One way I could think of to do this would be to build a map with each
unique item as a key and the count as its value. Then it would be
trivial to pull out the keys with the count as a specified value. I
started writing this, but my SLIME is royally screwed up right now
after the upgrade to Clojure HEAD. Sorry. Anyway, it shouldn't require
any refs - probably just a loop/recur.

Or maybe someone has a far more clever idea. :)

> On Sun, Nov 16, 2008 at 12:02 PM, npt11tpn <[EMAIL PROTECTED]> wrote:
>
>
> Hi guys,
> This is my first post to the group, but have been following the
> discussions for almost a year. Many thanks to Rich Hickey for creating
> a fantastic future-proof language which is a pleasure to use and to
> the great community!
> The following function (as part of a chemistry-related application)
> filters the elements of a sequence that a repeated a specified number
> of times. Wondering if the function could be simplified and written
> without the reference (newseq).
> Thanks a lot!
> Nik
>
> (defn filter-repeats [seq n]
>  "Returns a vector of the elements of a sequence that are repeated n
> times"
>  (let [newseq (ref [])]
>(doseq [u (set seq)]
>  (when (= (count (filter #(= % u) seq)) n)
>(dosync (commute newseq conj u
>@newseq))
>
> Usage e.g.
> (filter-repeats '(2 3 1 4 2 2 4 3 5 ) 2)
> [3 4]
>
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Filter repeats

2008-11-16 Thread Rich Hickey



On Nov 16, 12:18 pm, "Craig Andera" <[EMAIL PROTECTED]> wrote:
> One way I could think of to do this would be to build a map with each
> unique item as a key and the count as its value. Then it would be
> trivial to pull out the keys with the count as a specified value. I
> started writing this, but my SLIME is royally screwed up right now
> after the upgrade to Clojure HEAD. Sorry. Anyway, it shouldn't require
> any refs - probably just a loop/recur.
>
> Or maybe someone has a far more clever idea. :)
>
> > On Sun, Nov 16, 2008 at 12:02 PM, npt11tpn <[EMAIL PROTECTED]> wrote:
>
> > Hi guys,
> > This is my first post to the group, but have been following the
> > discussions for almost a year. Many thanks to Rich Hickey for creating
> > a fantastic future-proof language which is a pleasure to use and to
> > the great community!
> > The following function (as part of a chemistry-related application)
> > filters the elements of a sequence that a repeated a specified number
> > of times. Wondering if the function could be simplified and written
> > without the reference (newseq).
> > Thanks a lot!
> > Nik
>
> > (defn filter-repeats [seq n]
> >  "Returns a vector of the elements of a sequence that are repeated n
> > times"
> >  (let [newseq (ref [])]
> >(doseq [u (set seq)]
> >  (when (= (count (filter #(= % u) seq)) n)
> >(dosync (commute newseq conj u
> >@newseq))
>
> > Usage e.g.
> > (filter-repeats '(2 3 1 4 2 2 4 3 5 ) 2)
> > [3 4]

(defn filter-repeats [n coll]
  (let [counts (reduce (fn [m k] (assoc m k (inc (m k 0
   {} coll)]
(for [[k v] counts :when (= v n)] k)))

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
-~--~~~~--~~--~--~---



Re: recur in catch and finally?

2008-11-16 Thread Stephen C. Gilardi

On Nov 16, 2008, at 4:23 AM, Meikel Brandmeyer wrote:

> I tried the following code, which is a valid loop, IMHO, since it
> doesn't leave the catch clause.
>
> (try
>  :xxx
>  (catch Exception e
>(loop [x e]
>  (if (nil? (.getCause x))
>x
>(recur (.getCause x))
>
> However I get:
>
> java.lang.UnsupportedOperationException: Cannot recur from catch/ 
> finally (NO_SOURCE_FILE:1)
>
> Is this intended?

Hi Meikel,

It is intended. Please see the discussion here:

http://groups.google.com/group/clojure/search?group=clojure&q=recur+catch&qt_g=Search+this+group

--Steve


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking for the inverse of slurp

2008-11-16 Thread Stuart Sierra

Yes, spit is in clojure.contrib.duck-streams.

Java doesn't support "~", but if you want the home directory you can
get it with
(System/getProperty "user.home")
-Stuart

On Nov 16, 9:18 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> Hi Ethan
>
> spit is in Clojure-contrib. I wouldn't expect Clojure to support OS-
> specific idioms like ~, because Java doesn't.
>
> Stuart
>
> > Has the inverse of slurp been added to the core libraries yet?  Like  
> > this:
>
> > (spit "Some text" "/foo.txt")
>
> > to make a file called 'foo.txt' containing "Some text".
>
> > By the way, it appears that Clojure (or Java) doesn't recognize ~, as
> > in (slurp "~/foo.txt").  True?
>
> > -~--~~~~--~~--~--~---
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: A value that equals everything, or, ignoring things in multi-dispatch

2008-11-16 Thread Stuart Sierra

All multimethods have :default as the default fallback value,
regardless of what the dispatch function is.  But I assume that only
works with single values.  Maybe what you want is TWO multimethods,
one that dispatches on the first value, then calls the second
multimethod to dispatch on the other value.
-S

On Nov 15, 2:36 pm, samppi <[EMAIL PROTECTED]> wrote:
> Is there a way to get a value—call it 'anything—so that (isa? anything
> x) is always true for any x?
>
> I need this for multimethod dispatch—sometimes, I want a method to
> ignore some of the stuff its dispatch function returns:
>
>   (defmulti a #(%1 %2))
>
>   (defmethod a [3 2] [x y] ...)
>
>   ; in this method, the second dispatch value is ignored and
>   ; the method matches any call whose first argument is 5
>
>   (defmethod a [5 anything] [x y] ...)
>
> I wish the _ symbol would do this, but it doesn't work (if practical,
> it'd be cool if it were implemented in the future :). Is there some
> sort of solution possible right now?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: reader macros

2008-11-16 Thread Stephen C. Gilardi

On Nov 16, 2008, at 8:55 AM, Rich Hickey wrote:

> I've added #! as a to-end-of-line comment, like ;

Very cool, thanks!

Now, with Clojure compiled into its jar and the associated faster  
launching, it's reasonable to think of using Clojure for more tasks  
that might otherwise be done with bash/perl/python.

That would require a way (ideally built into the standard clojure.jar)  
for Clojure to read a script from stdin, execute it, and exit. Would  
this be best done by enhancing clojure.lang.Script or by providing a  
new "main" tailor made for it?

I'm in favor enhancing clojure.lang.Script.

Does anyone have any thoughts about this?

Does anyone with a Contributor Agreement in place already have code  
for it they'd like to propose?

--Steve


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Allowing she-bang lines?

2008-11-16 Thread Stuart Sierra

One (hackish) solution would be to write a wrapper script in some
other scripting language that chops off the #! line before running
Clojure.

But maybe, as a special case, the Clojure reader could ignore #! on
the first line.  I think some Schemes do that.
-S

On Nov 15, 7:52 pm, Jeff Rose <[EMAIL PROTECTED]> 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
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Allowing she-bang lines?

2008-11-16 Thread Stuart Sierra

Whoops, just saw:
On Nov 16, 2008, at 8:55 AM, Rich Hickey wrote:
> I've added #! as a to-end-of-line comment, like ;
So never mind.  Thanks, Rich!
-S

On Nov 16, 1:12 pm, Stuart Sierra <[EMAIL PROTECTED]> wrote:
> One (hackish) solution would be to write a wrapper script in some
> other scripting language that chops off the #! line before running
> Clojure.
>
> But maybe, as a special case, the Clojure reader could ignore #! on
> the first line.  I think some Schemes do that.
> -S
>
> On Nov 15, 7:52 pm, Jeff Rose <[EMAIL PROTECTED]> 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
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Running Clojure scripts at the command line

2008-11-16 Thread Stuart Sierra

On Nov 16, 1:09 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> Now, with Clojure compiled into its jar and the associated faster  
> launching, it's reasonable to think of using Clojure for more tasks  
> that might otherwise be done with bash/perl/python.
>
> That would require a way (ideally built into the standard clojure.jar)
> for Clojure to read a script from stdin, execute it, and exit. Would
> this be best done by enhancing clojure.lang.Script or by providing a
> new "main" tailor made for it?

Yes, yes!  My suggestion would be to modify clojure.lang.Script to
make it work like bash/perl/ruby; i.e., script is first argument,
command-line args follow, if no args at all read script from STDIN.

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.

-Stuart Sierra
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Improved exception reporting

2008-11-16 Thread Stuart Sierra

On Nov 16, 8:33 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> I'm certainly interested in improving the error reporting, but in this
> partiicular case:
>
>  java.lang.ClassCastException: clojure.lang.LazyCons
>
> is my all-time pet-peeve exception message, and it comes from the JVM.
> Why on earth they didn't report the types of both what you had and
> what you were trying to cast to is completely baffling and can only be
> described as a bug, which seems to be fixed in JDK 6, which reports
> "XXX cannot be cast to YYY".

Nice to know this has a solution.  Two other messages spring to mind
as tricky to diagnose, don't know if the JVM makes it possible to
improve them:

1. NullPointerException: Where did it come from?  What was null?  This
is tough, since the nil could have been returned by some distant
function.  Probably not easy to fix.

2. user=> (BigDecimal/valueOf 2)
java.lang.IllegalArgumentException: No matching method found: valueOf

The problem there is that BigDecimal.valueOf takes only a double or
long, not an Integer.  This is pretty uncommon in the standard Java
APIs, but some libraries have the same method repeated with a bunch of
different argument types.  Often it's hard to figure out why Clojure
can't find the right method.  Not sure exactly how to make this
easier, maybe if the error reported the full method signature it was
trying to find, e.g. "No matching method found valueOf
(java.lang.Integer)"

-Stuart Sierra
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: recur in catch and finally?

2008-11-16 Thread Meikel Brandmeyer

Hi Stephen,

Am 16.11.2008 um 18:55 schrieb Stephen C. Gilardi:

Is this intended?

It is intended. Please see the discussion here:

http://groups.google.com/group/clojure/search?group=clojure&q=recur+catch&qt_g=Search+this+group


I skimmed through the thread, and it seems the discussion is
for the following case:

(loop [...]
  (try
...
(catch ... (recur ...

I wouldn't expect this to work. However in my case the structure
was:

(try
  ...
  (catch ... (loop [...] (recur ...

So the loop did not cross the catch clause. From theoretic
point of view, I don't see a reason, why this should not be
possible. From a practical point of view there might be well
a reason why this prohibited.  But then it should be mentioned
in the docs: "no loop inside catch".

Sincerely
Meikel




smime.p7s
Description: S/MIME cryptographic signature


Re: Stupid Newbie Question-- Auto Indenting in SLIME -- Fixed

2008-11-16 Thread Peter Wolf

This is for the other NOOBs...

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 
 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


Peter Wolf wrote:
> OK, I think I found the problem.  When I start SLIME I get this...  
> See below for my .emacs
>
> 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: 
> 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)
>
>
> Peter Wolf wrote:
>> Hello, I'm feeling dumb...
>>
>> 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
>>
>>
>
>


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: recur in catch and finally?

2008-11-16 Thread Stephen C. Gilardi

On Nov 16, 2008, at 1:44 PM, Meikel Brandmeyer wrote:

> I skimmed through the thread, and it seems the discussion is
> for the following case:
>
> (loop [...]
>  (try
>...
>(catch ... (recur ...
>
> I wouldn't expect this to work. However in my case the structure
> was:
>
> (try
>  ...
>  (catch ... (loop [...] (recur ...
>
> So the loop did not cross the catch clause. From theoretic
> point of view, I don't see a reason, why this should not be
> possible.

Right you are, I had missed that distinction between the two cases.  
Now it looks to me like your code should work and that the test for  
recur in catch should be refined to detect the case where recur  
destination is also in the catch and allow that.

--Steve


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Stupid Newbie Question-- Auto Indenting in SLIME -- Fixed

2008-11-16 Thread Matt Revelle

On Nov 16, 2008, at 2:40 PM, Peter Wolf <[EMAIL PROTECTED]> wrote:

>
> This is for the other NOOBs...
>
> Apparently to use SLIME with Clojure, you need to install a Common  
> Lisp.

This is not the case.

>
>
> I assumed that SLIME was written in EMACS Lisp, but apparently not.   
> In
> his Blog, Bill did say

You need to install SLIME, but not a Common Lisp.  SLIME includes  
swank implementations for a variety of Common Lisps but not Clojure.   
The swank-clojure project is what allows Clojure to communicate with  
SLIME.

>
>
>"If you already use a CL implementation with 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
>
>
> Peter Wolf wrote:
>> OK, I think I found the problem.  When I start SLIME I get this...
>> See below for my .emacs
>>
>> 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: 
>> 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)
>>
>>
>> Peter Wolf wrote:
>>> Hello, I'm feeling dumb...
>>>
>>> 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
>>>
>>>
>>
>>
>
>
> >

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: A value that equals everything, or, ignoring things in multi-dispatch

2008-11-16 Thread notallama

what i think would be nice here is multimethods taking multiple
dispatch functions. (i'm not sure how you'd do that without breaking
the default value syntax)

so it'd try the first function, and if it doesn't match any method,
then it tries the second, etc. then :default, then throws an exception.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Filter repeats

2008-11-16 Thread npt11tpn


Brilliant, thank you very much!
Nik

On Nov 16, 5:41 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Nov 16, 12:18 pm, "Craig Andera" <[EMAIL PROTECTED]> wrote:
>
>
>
> > One way I could think of to do this would be to build a map with each
> > unique item as a key and the count as its value. Then it would be
> > trivial to pull out the keys with the count as a specified value. I
> > started writing this, but my SLIME is royally screwed up right now
> > after the upgrade to Clojure HEAD. Sorry. Anyway, it shouldn't require
> > any refs - probably just a loop/recur.
>
> > Or maybe someone has a far more clever idea. :)
>
> > > On Sun, Nov 16, 2008 at 12:02 PM, npt11tpn <[EMAIL PROTECTED]> wrote:
>
> > > Hi guys,
> > > This is my first post to the group, but have been following the
> > > discussions for almost a year. Many thanks to Rich Hickey for creating
> > > a fantastic future-proof language which is a pleasure to use and to
> > > the great community!
> > > The following function (as part of a chemistry-related application)
> > > filters the elements of a sequence that a repeated a specified number
> > > of times. Wondering if the function could be simplified and written
> > > without the reference (newseq).
> > > Thanks a lot!
> > > Nik
>
> > > (defn filter-repeats [seq n]
> > >  "Returns a vector of the elements of a sequence that are repeated n
> > > times"
> > >  (let [newseq (ref [])]
> > >    (doseq [u (set seq)]
> > >      (when (= (count (filter #(= % u) seq)) n)
> > >        (dosync (commute newseq conj u
> > >   [EMAIL PROTECTED]))
>
> > > Usage e.g.
> > > (filter-repeats '(2 3 1 4 2 2 4 3 5 ) 2)
> > > [3 4]
>
> (defn filter-repeats [n coll]
>   (let [counts (reduce (fn [m k] (assoc m k (inc (m k 0
>                        {} coll)]
>     (for [[k v] counts :when (= v n)] k)))
>
> 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
-~--~~~~--~~--~--~---



Re: Looking for the inverse of slurp

2008-11-16 Thread Ethan Herdrick

Thanks, Stuarts!

On Nov 16, 10:06 am, Stuart Sierra <[EMAIL PROTECTED]>
wrote:
> Yes, spit is in clojure.contrib.duck-streams.
>
> Java doesn't support "~", but if you want the home directory you can
> get it with
> (System/getProperty "user.home")
> -Stuart
>
> On Nov 16, 9:18 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
>
> > Hi Ethan
>
> > spit is in Clojure-contrib. I wouldn't expect Clojure to support OS-
> > specific idioms like ~, because Java doesn't.
>
> > Stuart
>
> > > Has the inverse of slurp been added to the core libraries yet?  Like  
> > > this:
>
> > > (spit "Some text" "/foo.txt")
>
> > > to make a file called 'foo.txt' containing "Some text".
>
> > > By the way, it appears that Clojure (or Java) doesn't recognize ~, as
> > > in (slurp "~/foo.txt").  True?
>
> > > -~--~~~~--~~--~--~---
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Improved exception reporting

2008-11-16 Thread Howard Lewis Ship

Another idea I had was this (and I haven't had a chance to check the
source code to see if any of this is already implemented):

When Clojure creates a new Java class for a function, it should find a
way to hang the meta-data for the function as a static field on the
function.  Alternately, there should be an API that takes a generated
function class (or even function class name) and returns the meta
data.

A  print-stack-trace function would take apart the stack trace, and
for Clojure function classes, substitute something meaningful for
those frames, such as the namespace qualified name and file/line
number. In other words, identify the class name from the Java
StackFrame element, find the meta-data for the originating function,
pretty print that in place of the normal Java stack frame.

On Sun, Nov 16, 2008 at 5:33 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
>
>
> On Nov 14, 3:50 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
>> On Nov 14, 2008, at 3:11 PM, Howard Lewis Ship wrote:
>>
>> > The point is, an exception that said something like:
>>
>> > "Expected java.lang.Comparable but received :king" would have helped
>> > me unravel this much, much easier!
>>
>> I agree. Clojure should give all the information it can about the
>> object(s) involved in the failure. There are other places where the
>> class of the object is given, but not its string representation. Any
>> juicy info that's easily available should be made part of the
>> exception message.
>
> I'm certainly interested in improving the error reporting, but in this
> partiicular case:
>
>  java.lang.ClassCastException: clojure.lang.LazyCons
>
> is my all-time pet-peeve exception message, and it comes from the JVM.
> Why on earth they didn't report the types of both what you had and
> what you were trying to cast to is completely baffling and can only be
> described as a bug, which seems to be fixed in JDK 6, which reports
> "XXX cannot be cast to YYY".
>
> For every library and every app to have to wrap every cast in a try
> block simply in order to get this message to say what it ought to is
> not productive, IMO.
>
> One issue with trying to capture string representations is that they
> can be arbitrarily long.

Certainly; I think you would want to have a way of converting an
object to a "short" string description.  Most Java objects would
accomplish this with just toString(), but some kind of marker
interface (perhaps) on the list, set, etc. would be necessary. .. when
present, RT would supply a shorter reprsentation, or just an
indication of the type.

Certainly, an endless lazy sequence would be problematic!

>
> Rich
>
> >
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Running Clojure scripts at the command line

2008-11-16 Thread Howard Lewis Ship

On Sun, Nov 16, 2008 at 10:21 AM, Stuart Sierra
<[EMAIL PROTECTED]> wrote:
>
>
> 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.

+1


-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: reader macros

2008-11-16 Thread Jeff Rose

Rich Hickey wrote:
> I've added #! as a to-end-of-line comment, like ;

[EMAIL PROTECTED]:~/projects/languages/clojure$ cat foo
#!/usr/bin/env clj

(println "Hello World!")
[EMAIL PROTECTED]:~/projects/languages/clojure$ chmod u+x foo
[EMAIL PROTECTED]:~/projects/languages/clojure$ ./foo
Hello World!

---

Awesome.  Thanks Rich.

-Jeff

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Running Clojure scripts at the command line

2008-11-16 Thread Stephen C. Gilardi

On Nov 16, 2008, at 1:21 PM, Stuart Sierra wrote:

> 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.

One canonical, flexible main sounds good to me too. I was mistaken  
about how things work now, though. With Rich's change today, the  
following already works as an executable script (hello.clj):

#!/usr/bin/env java -cp /sq/ext/clojure/clojure.jar clojure.lang.Script
(println "Hello, cores!")

For me, that launches and runs in about 1.1 seconds of real time.

Cool!

--Steve


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Clojure for LISP programmers....

2008-11-16 Thread Simon Brooke

Has anyone written a very simple introduction to Clojure for LISP
hackers? I've spend an evening playing with it pretty intensively, and
thus far I haven't got a thing to work. I've read
http://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_Lisp_Programmers,
but it hasn't helped me.

In LISP:

* (defun fact (n) (cond ((= 1 n) 1)(t (* n (fact (- n 1))
FACT
* (fact 10)
3628800

that is Common LISP, but what the hell; in Portable Standard LISP it
would have been identical except 'de' instead of 'defun'; in Scheme
it's a little different:

> (define (fact n) (cond ((= n 1) 1)(#t (* n (fact (- n 1))
> (fact 10)
3628800

But the family resemblance is there... So, let's try it in Clojure:

user=> (defun fact (n) (cond ((= n 1) 1) (t (* n (fact (- n 1))
java.lang.Exception: Unable to resolve symbol: defun in this context
user=> (de fact (n) ( cond ((= n 1) 1) (t (* n (fact (- n 1))
java.lang.Exception: Unable to resolve symbol: de in this context
user=> (def fact (n) ( cond ((= n 1) 1) (t (* n (fact (- n 1))
java.lang.Exception: Too many arguments to def
user=> (defn fact [n] (cond ((= n 1) 1)(t (* n (fact (- n 1))
java.lang.Exception: Unable to resolve symbol: t in this context
user=> (defn fact [n](cond ((= n 1) 1)(#t  (* n (fact (- n 1))
java.lang.Exception: No dispatch macro for: t
user=> (defn fact [n](cond ((= n 1) 1)(#true (* n (fact (- n 1))
java.lang.Exception: No dispatch macro for: t
user=> (defn fact [n] (cond ((= n 1) 1)(true (* n (fact (- n 1))
#'user/fact

OK, what's with the funny square brackets? A sequence of forms
enclosed in square brackets is a vector, not a list. Why is the
arglist for a function a vector? For now let's accept that it is, and
pass on.

user=> (fact 10)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.IFn

OK, so that doesn't work. As Zaphod memorably put it, 'hey, what is
truth, man?' Good question:

user=> (true? 'true)
true
user=> (true? true)
true
user=> (true? t)
java.lang.Exception: Unable to resolve symbol: t in this context
user=> (true? 't)
false
user=> (def t 'true)
#'user/t
user=> (true? t)
true

OK, now we know the truth, surely we can write a valid fact?

user=> (defn fact [n] (cond ((= n 1) 1)('true (* n (fact (- n 1))
#'user/fact
user=> (fact 10)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.IFn
user=> (defn fact [n] (cond ((= n 1) 1)((true? 'true) (* n (fact (- n
1))
#'user/fact
user=> (fact 10)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.IFn

OK, it looks like whatever's causing the break isn't the guard on the
second cond branch. Let's for a moment try something that's purely
boolean:

user=> (defn band [l] (cond ((nil? l) true)((true? (car l))(band (cdr
l)
java.lang.Exception: Unable to resolve symbol: cdr in this context

No CDR? It's LISP, but it can't fetch the contents of the decrement
register? fifty years of LISP history tossed into the dirt. So if the
CDR isn't called the CDR, what is it called (and what's the CDADR
called)?

user=> (defn band [l] (cond ((nil? l) true)((true? (first l))(band
(rest l)
#'user/band
user=> (band '(true true true))
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.IFn

OK, can we write any function at all that works?

user=> (defn square [n] (* n n))
#'user/square
user=> (square 4)
16

Fine, so recurse up from that:

user=> (defn power [n m] (cond ((= m 0) 1)(true (* n (power n (- m
1))
#'user/power
user=> (power 2 2)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to
clojure.lang.IFn

Aggghhh...

Getting LISP to work seamlessly inside a Java environment with easy
intercalling between LISP and Java is a very big win, and potentially
knocks things like JScheme and Armed Bear Common LISP into a cocked
hat...

But it would be nice to be able to get started!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Compojure and Clojure 1094+

2008-11-16 Thread J . Pablo Fernández

Hello,

I've just forked Compojure and made it work with Clojure 1094+, the
change is here:

http://github.com/pupeno/compojure/commit/3cac756c89f63bbe009dcb6abbeb4646c252dee4

I haven't updated the clojure.jar and clojure-contrib.jar because I
don't believe Compojure should distribute those or any other jars at
all, so I'm moving my fork into the direction where it would be only a
library. Nevertheless, that patch can be pulled in to have Clojure
1094+ in any repo.

Enjoy!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Stupid Newbie Question-- Auto Indenting in SLIME

2008-11-16 Thread David Nolen
I think the latest version of clojure and swank-clojure also requires
something like this line in your emacs file:
(setq swank-clojure-extra-classpaths (list "/path/to/clojure/classes"))

Personally I use the clojure git mirror hosted on github as well as git
clone's of clojure-mode and swank-clojure.  This way I can just git pull to
make sure everything is the latest.

David

On Sun, Nov 16, 2008 at 11:26 AM, Peter Wolf <[EMAIL PROTECTED]> wrote:

>
> OK, I think I found the problem.  When I start SLIME I get this...  See
> below for my .emacs
>
> 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: 
> 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)
>
>
> Peter Wolf wrote:
> > Hello, I'm feeling dumb...
> >
> > 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
> >
> >
>
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Stupid Newbie Question-- Auto Indenting in SLIME -- Fixed

2008-11-16 Thread Bill Clementson

Hi Peter,

On Sun, Nov 16, 2008 at 11:40 AM, Peter Wolf <[EMAIL PROTECTED]> 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
>  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

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Clojure for LISP programmers....

2008-11-16 Thread Brian W

I'm going to assume this is serious and not a joke, but you do realize
Clojure is already quite well documented at clojure.org?

#t  t => true
define  defun  =>defn
car, cdr, caar, etc.   ~>  first, rest, ffirst, rrest, frest, rfirst

arglists are vectors because [ ] stand out better

On Nov 16, 2:31 pm, Simon Brooke <[EMAIL PROTECTED]> wrote:
> Has anyone written a very simple introduction to Clojure for LISP
> hackers? I've spend an evening playing with it pretty intensively, and
> thus far I haven't got a thing to work. I've 
> readhttp://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_L...,
> but it hasn't helped me.
>
> In LISP:
>
> * (defun fact (n) (cond ((= 1 n) 1)(t (* n (fact (- n 1))
> FACT
> * (fact 10)
> 3628800
>
> that is Common LISP, but what the hell; in Portable Standard LISP it
> would have been identical except 'de' instead of 'defun'; in Scheme
> it's a little different:
>
> > (define (fact n) (cond ((= n 1) 1)(#t (* n (fact (- n 1))
> > (fact 10)
>
> 3628800
>
> But the family resemblance is there... So, let's try it in Clojure:
>
> user=> (defun fact (n) (cond ((= n 1) 1) (t (* n (fact (- n 1))
> java.lang.Exception: Unable to resolve symbol: defun in this context
> user=> (de fact (n) ( cond ((= n 1) 1) (t (* n (fact (- n 1))
> java.lang.Exception: Unable to resolve symbol: de in this context
> user=> (def fact (n) ( cond ((= n 1) 1) (t (* n (fact (- n 1))
> java.lang.Exception: Too many arguments to def
> user=> (defn fact [n] (cond ((= n 1) 1)(t (* n (fact (- n 1))
> java.lang.Exception: Unable to resolve symbol: t in this context
> user=> (defn fact [n](cond ((= n 1) 1)(#t  (* n (fact (- n 1))
> java.lang.Exception: No dispatch macro for: t
> user=> (defn fact [n](cond ((= n 1) 1)(#true (* n (fact (- n 1))
> java.lang.Exception: No dispatch macro for: t
> user=> (defn fact [n] (cond ((= n 1) 1)(true (* n (fact (- n 1))
> #'user/fact
>
> OK, what's with the funny square brackets? A sequence of forms
> enclosed in square brackets is a vector, not a list. Why is the
> arglist for a function a vector? For now let's accept that it is, and
> pass on.
>
> user=> (fact 10)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.IFn
>
> OK, so that doesn't work. As Zaphod memorably put it, 'hey, what is
> truth, man?' Good question:
>
> user=> (true? 'true)
> true
> user=> (true? true)
> true
> user=> (true? t)
> java.lang.Exception: Unable to resolve symbol: t in this context
> user=> (true? 't)
> false
> user=> (def t 'true)
> #'user/t
> user=> (true? t)
> true
>
> OK, now we know the truth, surely we can write a valid fact?
>
> user=> (defn fact [n] (cond ((= n 1) 1)('true (* n (fact (- n 1))
> #'user/fact
> user=> (fact 10)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.IFn
> user=> (defn fact [n] (cond ((= n 1) 1)((true? 'true) (* n (fact (- n
> 1))
> #'user/fact
> user=> (fact 10)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.IFn
>
> OK, it looks like whatever's causing the break isn't the guard on the
> second cond branch. Let's for a moment try something that's purely
> boolean:
>
> user=> (defn band [l] (cond ((nil? l) true)((true? (car l))(band (cdr
> l)
> java.lang.Exception: Unable to resolve symbol: cdr in this context
>
> No CDR? It's LISP, but it can't fetch the contents of the decrement
> register? fifty years of LISP history tossed into the dirt. So if the
> CDR isn't called the CDR, what is it called (and what's the CDADR
> called)?
>
> user=> (defn band [l] (cond ((nil? l) true)((true? (first l))(band
> (rest l)
> #'user/band
> user=> (band '(true true true))
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.IFn
>
> OK, can we write any function at all that works?
>
> user=> (defn square [n] (* n n))
> #'user/square
> user=> (square 4)
> 16
>
> Fine, so recurse up from that:
>
> user=> (defn power [n m] (cond ((= m 0) 1)(true (* n (power n (- m
> 1))
> #'user/power
> user=> (power 2 2)
> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
> clojure.lang.IFn
>
> Aggghhh...
>
> Getting LISP to work seamlessly inside a Java environment with easy
> intercalling between LISP and Java is a very big win, and potentially
> knocks things like JScheme and Armed Bear Common LISP into a cocked
> hat...
>
> But it would be nice to be able to get started!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Clojure for LISP programmers....

2008-11-16 Thread Dave Newton

I'll add that:

(cond (foo bar) (baz plugh)) => (cond (foo) (bar) (baz) (plugh))

This particular CL difference is listed on the wiki page you listed:

http://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_Lisp_Programmers

I also didn't have anywhere near these kinds of problems getting things to 
work, although I've been doing a lot of Java lately, and more Scheme than CL, 
so that may have helped.

I'm sure other folks would also be interested in your contributions towards a 
CL => Clojure document; sounds like a good opportunity.

Dave

--- On Sun, 11/16/08, Brian W <[EMAIL PROTECTED]> wrote:
> I'm going to assume this is serious and not a joke, but you do 
> realize Clojure is already quite well documented at clojure.org?
> 
> #t  t => true
> define  defun  =>defn
> car, cdr, caar, etc.   ~>  first, rest, ffirst, rrest,
> frest, rfirst
> 
> arglists are vectors because [ ] stand out better
> 
> On Nov 16, 2:31 pm, Simon Brooke
> <[EMAIL PROTECTED]> wrote:
> > Has anyone written a very simple introduction to
> Clojure for LISP
> > hackers? I've spend an evening playing with it
> pretty intensively, and
> > thus far I haven't got a thing to work. I've
> readhttp://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_L...,
> > but it hasn't helped me.
> >
> > In LISP:
> >
> > * (defun fact (n) (cond ((= 1 n) 1)(t (* n (fact (- n
> 1))
> > FACT
> > * (fact 10)
> > 3628800
> >
> > that is Common LISP, but what the hell; in Portable
> Standard LISP it
> > would have been identical except 'de' instead
> of 'defun'; in Scheme
> > it's a little different:
> >
> > > (define (fact n) (cond ((= n 1) 1)(#t (* n (fact
> (- n 1))
> > > (fact 10)
> >
> > 3628800
> >
> > But the family resemblance is there... So, let's
> try it in Clojure:
> >
> > user=> (defun fact (n) (cond ((= n 1) 1) (t (* n
> (fact (- n 1))
> > java.lang.Exception: Unable to resolve symbol: defun
> in this context
> > user=> (de fact (n) ( cond ((= n 1) 1) (t (* n
> (fact (- n 1))
> > java.lang.Exception: Unable to resolve symbol: de in
> this context
> > user=> (def fact (n) ( cond ((= n 1) 1) (t (* n
> (fact (- n 1))
> > java.lang.Exception: Too many arguments to def
> > user=> (defn fact [n] (cond ((= n 1) 1)(t (* n
> (fact (- n 1))
> > java.lang.Exception: Unable to resolve symbol: t in
> this context
> > user=> (defn fact [n](cond ((= n 1) 1)(#t  (* n
> (fact (- n 1))
> > java.lang.Exception: No dispatch macro for: t
> > user=> (defn fact [n](cond ((= n 1) 1)(#true (* n
> (fact (- n 1))
> > java.lang.Exception: No dispatch macro for: t
> > user=> (defn fact [n] (cond ((= n 1) 1)(true (* n
> (fact (- n 1))
> > #'user/fact
> >
> > OK, what's with the funny square brackets? A
> sequence of forms
> > enclosed in square brackets is a vector, not a list.
> Why is the
> > arglist for a function a vector? For now let's
> accept that it is, and
> > pass on.
> >
> > user=> (fact 10)
> > java.lang.ClassCastException: java.lang.Boolean cannot
> be cast to
> > clojure.lang.IFn
> >
> > OK, so that doesn't work. As Zaphod memorably put
> it, 'hey, what is
> > truth, man?' Good question:
> >
> > user=> (true? 'true)
> > true
> > user=> (true? true)
> > true
> > user=> (true? t)
> > java.lang.Exception: Unable to resolve symbol: t in
> this context
> > user=> (true? 't)
> > false
> > user=> (def t 'true)
> > #'user/t
> > user=> (true? t)
> > true
> >
> > OK, now we know the truth, surely we can write a valid
> fact?
> >
> > user=> (defn fact [n] (cond ((= n 1) 1)('true
> (* n (fact (- n 1))
> > #'user/fact
> > user=> (fact 10)
> > java.lang.ClassCastException: java.lang.Boolean cannot
> be cast to
> > clojure.lang.IFn
> > user=> (defn fact [n] (cond ((= n 1) 1)((true?
> 'true) (* n (fact (- n
> > 1))
> > #'user/fact
> > user=> (fact 10)
> > java.lang.ClassCastException: java.lang.Boolean cannot
> be cast to
> > clojure.lang.IFn
> >
> > OK, it looks like whatever's causing the break
> isn't the guard on the
> > second cond branch. Let's for a moment try
> something that's purely
> > boolean:
> >
> > user=> (defn band [l] (cond ((nil? l) true)((true?
> (car l))(band (cdr
> > l)
> > java.lang.Exception: Unable to resolve symbol: cdr in
> this context
> >
> > No CDR? It's LISP, but it can't fetch the
> contents of the decrement
> > register? fifty years of LISP history tossed into the
> dirt. So if the
> > CDR isn't called the CDR, what is it called (and
> what's the CDADR
> > called)?
> >
> > user=> (defn band [l] (cond ((nil? l) true)((true?
> (first l))(band
> > (rest l)
> > #'user/band
> > user=> (band '(true true true))
> > java.lang.ClassCastException: java.lang.Boolean cannot
> be cast to
> > clojure.lang.IFn
> >
> > OK, can we write any function at all that works?
> >
> > user=> (defn square [n] (* n n))
> > #'user/square
> > user=> (square 4)
> > 16
> >
> > Fine, so recurse up from that:
> >
> > user=> (defn power [n m] (cond ((= m 0) 1)(true (*
> n (power n (- m
> > 

Re: recur in catch and finally?

2008-11-16 Thread Chouser

On Sun, Nov 16, 2008 at 4:23 AM, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I tried the following code, which is a valid loop, IMHO, since it
> doesn't leave the catch clause.
>
> (try
>  :xxx
>  (catch Exception e
>(loop [x e]
>  (if (nil? (.getCause x))
>x
>(recur (.getCause x))
>
> However I get:
>
> java.lang.UnsupportedOperationException: Cannot recur from catch/finally
> (NO_SOURCE_FILE:1)
>
> Is this intended?

You could of course work around this by putting your loop in some
other function and calling it from inside catch.

--Chouser

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



clojure.contrib.test-is changes

2008-11-16 Thread Stuart Sierra

Hi folks, I made some small changes to clojure.contrib.test-is:

1. *test-out* now defaults to standard output (instead of standard
error). This should be better for SLIME users.

2. Based on Frantisek Sodomka's suggestions, I've added two
convenience macros, each= and all-true:

user=> (doc all-true)
-
clojure.contrib.test-is/all-true
([& body])
Macro
  Convenience macro; every body expression is tested as with 'is'.
nil
user=> (doc each=)
-
clojure.contrib.test-is/each=
([& forms])
Macro
  Convenience macro for doing a bunch of equality tests.  Same as
  doing (is (= ...)) on each pair.

  (each= (test-expr-1) expected-value1
 (test-expr-2) expected-value2
 (test-expr-3) expected-value3)

I also modified test_clojure/numbers to demonstrate use of all-true.

I though about calling it "are", since it's like a plural form of
"is", but I thought that might be confusing for non-native-English
speakers.

I have committed these changes ONLY in the new, no-namespace-directory
files.

-Stuart
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Patch: standalone compiler (almost)

2008-11-16 Thread Stuart Sierra
Hi Rich, and all,

I took a stab at writing a static compiler class, i.e. a main() that
just compiles all the .clj files on the command line and saves the
.class files.  Patch attached.

It almost works.  The only thing that seems to be missing is creating
the class for the namespace itself, like "clojure/core.class".  Not
sure what needs to be added to make that work.

-Stuart Sierra

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



compiler.patch
Description: Binary data


Re: offtopic - where are you come from? (poll)

2008-11-16 Thread Giancarlo Angulo
manila, philippines!
=
ANGOL
=
-|[EMAIL PROTECTED], =|+^_^X++~_~,@-

"The only thing worse than a hopeless romantic is a hopeful one"

Magbasa bago Mamuna. Mag-isip bago mambatikos

Without Truth there is no Justice,
Without Justice, there is Tyranny

Semper fi

Proof of Desire is Pursuit

www.onthe8spot.com
[EMAIL PROTECTED]
09173822367


On Sun, Nov 16, 2008 at 10:00 PM, mehrheit <[EMAIL PROTECTED]> wrote:

>
> Vilnius, Lithuania here.
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Patch: standalone compiler (almost)

2008-11-16 Thread Rich Hickey



On Nov 16, 9:47 pm, "Stuart Sierra" <[EMAIL PROTECTED]>
wrote:
> Hi Rich, and all,
>
> I took a stab at writing a static compiler class, i.e. a main() that
> just compiles all the .clj files on the command line and saves the
> .class files.  Patch attached.
>
> It almost works.  The only thing that seems to be missing is creating
> the class for the namespace itself, like "clojure/core.class".  Not
> sure what needs to be added to make that work.
>

Interesting.

I think you've hooked in at the wrong point - better to grab the
clojure.core/compile var and call that. You should also keep the unit
of compilation the lib, not files.

Since it only requires main, might I suggest you write this in Clojure
instead?

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
-~--~~~~--~~--~--~---



Re: Clojure for LISP programmers....

2008-11-16 Thread Luc Prefontaine
I never read anywhere in the documentation or in the user group that
Clojure is a Common LISP implementation.

Since it's existence, LISP has not gained a large acceptance in the
commercial market compared to other "conventional" programming
languages.
I started to use it 28 years ago (UCI Lisp on a DEC10) and never crossed
over it in my professional work except twice
(ITA implemented their services in LISP and it is a big commercial
success and another of my customer uses Scheme to implement
some specialized algorithms).
For a language that's been around for 50 years, it's at least annoying
if not strange given the power of the language.
Worse some companies have success stories using LISP but don't go public
about it.

Certainly, having "t" to represent the truth value instead of "true",
using defun instead of defn or making an indigestion of parenthesis
are not essential LISP features.

Compromises at the syntax level are very small concessions to get LISP
endorsed by a majority in the software community.
The post fix notation is already a challenge (look back at people using
HP calculators in the 70s/80s), so lets make things a bit easier for
the non LISP programmer used to left-right assignments...
Clojure is not a second citizen LISP because it implements a simplified
syntax.

You may need to start from a blank sheet if your Common Lisp knowledge
interferes with your learning curve :)))
Get Stuart's book http://pragprog.com/titles/shcloj/programming-clojure
and start from there.
This should give you a clear vision of what Clojure is and is not.

It's time for LISP to get a significant share of commercial success
stories and the only way is to add some sex appeal to it to 
attract the masses. Considering that the software industry stagnates
since the 1980s, it's a welcomed change.

Personally, Clojure is the breath of fresh air I was waiting for. The
reality is that most of my customers are using Java with
thousands of code lines with pitiful results in terms of ROI. According
to them, Java is the best gizmo on the market (including
all the frameworks written around it), I think that Cobol had a better
ROI than Java in many instances.
Getting them away from Java is impossible to do but something like
Clojure is an open door to a lot of significant applications,
better ROI and better time to market schedules.

I think that Clojure's main audience are these people drowning in this
ocean of java code, not the LISP advocates :)))

Luc



On Sun, 2008-11-16 at 15:32 -0800, Dave Newton wrote:

> I'll add that:
> 
> (cond (foo bar) (baz plugh)) => (cond (foo) (bar) (baz) (plugh))
> 
> This particular CL difference is listed on the wiki page you listed:
> 
> http://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_Lisp_Programmers
> 
> I also didn't have anywhere near these kinds of problems getting things to 
> work, although I've been doing a lot of Java lately, and more Scheme than CL, 
> so that may have helped.
> 
> I'm sure other folks would also be interested in your contributions towards a 
> CL => Clojure document; sounds like a good opportunity.
> 
> Dave
> 
> --- On Sun, 11/16/08, Brian W <[EMAIL PROTECTED]> wrote:
> > I'm going to assume this is serious and not a joke, but you do 
> > realize Clojure is already quite well documented at clojure.org?
> > 
> > #t  t => true
> > define  defun  =>defn
> > car, cdr, caar, etc.   ~>  first, rest, ffirst, rrest,
> > frest, rfirst
> > 
> > arglists are vectors because [ ] stand out better
> > 
> > On Nov 16, 2:31 pm, Simon Brooke
> > <[EMAIL PROTECTED]> wrote:
> > > Has anyone written a very simple introduction to
> > Clojure for LISP
> > > hackers? I've spend an evening playing with it
> > pretty intensively, and
> > > thus far I haven't got a thing to work. I've
> > readhttp://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_L...,
> > > but it hasn't helped me.
> > >
> > > In LISP:
> > >
> > > * (defun fact (n) (cond ((= 1 n) 1)(t (* n (fact (- n
> > 1))
> > > FACT
> > > * (fact 10)
> > > 3628800
> > >
> > > that is Common LISP, but what the hell; in Portable
> > Standard LISP it
> > > would have been identical except 'de' instead
> > of 'defun'; in Scheme
> > > it's a little different:
> > >
> > > > (define (fact n) (cond ((= n 1) 1)(#t (* n (fact
> > (- n 1))
> > > > (fact 10)
> > >
> > > 3628800
> > >
> > > But the family resemblance is there... So, let's
> > try it in Clojure:
> > >
> > > user=> (defun fact (n) (cond ((= n 1) 1) (t (* n
> > (fact (- n 1))
> > > java.lang.Exception: Unable to resolve symbol: defun
> > in this context
> > > user=> (de fact (n) ( cond ((= n 1) 1) (t (* n
> > (fact (- n 1))
> > > java.lang.Exception: Unable to resolve symbol: de in
> > this context
> > > user=> (def fact (n) ( cond ((= n 1) 1) (t (* n
> > (fact (- n 1))
> > > java.lang.Exception: Too many arguments to def
> > > user=> (defn fact [n] (cond ((= n 1) 1)(t (* n
> > (fact (- n 1))
> > > java.lang.Exce

Re: Patch: standalone compiler (almost)

2008-11-16 Thread mac



On Nov 17, 4:34 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Nov 16, 9:47 pm, "Stuart Sierra" <[EMAIL PROTECTED]>
> wrote:
>
> > Hi Rich, and all,
>
> > I took a stab at writing a static compiler class, i.e. a main() that
> > just compiles all the .clj files on the command line and saves the
> > .class files.  Patch attached.
>
> > It almost works.  The only thing that seems to be missing is creating
> > the class for the namespace itself, like "clojure/core.class".  Not
> > sure what needs to be added to make that work.
>
> Interesting.
>
> I think you've hooked in at the wrong point - better to grab the
> clojure.core/compile var and call that. You should also keep the unit
> of compilation the lib, not files.
>
> Since it only requires main, might I suggest you write this in Clojure
> instead?
>
> Rich

This would be a much welcome addition because as someone who is
writing small desktop apps with clojure it would be great if the
startup time could be reduced and I'm guessing it would help a bunch
to not have to wait for all the code to compile from text every time?

/Markus

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: recur in catch and finally?

2008-11-16 Thread mb

Hi,

On 17 Nov., 02:09, Chouser <[EMAIL PROTECTED]> wrote:
> You could of course work around this by putting your loop in some
> other function and calling it from inside catch.

In this specific case I used:
(last (take-while #(not (nil? %)) (iterate #(.getCause %) e)))

However, a separate function would also work. That is not
the point. One can work around it. But I try to follow the
principle of least surprise as much as possible. So when
valid looking code doesn't work for an obscure reason, this
certainly is a surprise.

I have no problem putting the loop into a dedicated function.
Or find some equivalent way to express it. However then it
should be documented somewhere, that this is actually
necessary. ("for technical reasons loop/recur cannot be
used in/at/for")

Sincerely
Meikel


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Clojure for LISP programmers....

2008-11-16 Thread mb

Hi Simon,

there is a detailed explanation of syntax, data
structures etc. as well as a complete reference
at the Clojure site[1].

Then there's a wiki[2] with a lot of information of
setting Clojure up with different editors like emacs
or vim and a lot of examples. Also explaining
some of the quirks like missing TCO due to the
underlying JVM.

Rich held a talk at the Boston Lisp Group. So
when you have a Lisp background you might
certainly be interested in this, since the audience
was also quite familiar with Lisp. The talk was
recorded and is available at blip.tv[3]. There
are also other talks, eg. Rich's concurrency talk
with the famous ant simulation, which might
be interesting. Google probably knows where
to get those.

For live experience there is the #clojure channel
on freenode. The people there are alway helpful.
So in case you have a problem, you can get
real-time help from them. Rich is also quite
active there. So feedback reaches the right
people.

And finally (as you already did) you might post
your questions here on the list.

Hope this helps to get going with Clojure. :)

Sincerely
Meikel

[1]: http://clojure.org
[2]: http://en.wikibooks.org/wiki/Clojure_Programming
[3]: http://blip.tv/file/1313398


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Clojure for LISP programmers....

2008-11-16 Thread Howard Lewis Ship

I generally like that Clojure dispenses with parens that exist for the
benefit of the evaluator rather than the developer; thus far fewer
parens when using (cond).  Still, my old Lisp habits (20 years without
use) succumbed as much as Simons.  See my earlier thread about
exception reporting.

Could Clojure display errors like "seems like you're coding up some
Common Lisp here"?

On Sun, Nov 16, 2008 at 3:01 PM, Brian W <[EMAIL PROTECTED]> wrote:
>
> I'm going to assume this is serious and not a joke, but you do realize
> Clojure is already quite well documented at clojure.org?
>
> #t  t => true
> define  defun  =>defn
> car, cdr, caar, etc.   ~>  first, rest, ffirst, rrest, frest, rfirst
>
> arglists are vectors because [ ] stand out better
>
> On Nov 16, 2:31 pm, Simon Brooke <[EMAIL PROTECTED]> wrote:
>> Has anyone written a very simple introduction to Clojure for LISP
>> hackers? I've spend an evening playing with it pretty intensively, and
>> thus far I haven't got a thing to work. I've 
>> readhttp://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_L...,
>> but it hasn't helped me.
>>
>> In LISP:
>>
>> * (defun fact (n) (cond ((= 1 n) 1)(t (* n (fact (- n 1))
>> FACT
>> * (fact 10)
>> 3628800
>>
>> that is Common LISP, but what the hell; in Portable Standard LISP it
>> would have been identical except 'de' instead of 'defun'; in Scheme
>> it's a little different:
>>
>> > (define (fact n) (cond ((= n 1) 1)(#t (* n (fact (- n 1))
>> > (fact 10)
>>
>> 3628800
>>
>> But the family resemblance is there... So, let's try it in Clojure:
>>
>> user=> (defun fact (n) (cond ((= n 1) 1) (t (* n (fact (- n 1))
>> java.lang.Exception: Unable to resolve symbol: defun in this context
>> user=> (de fact (n) ( cond ((= n 1) 1) (t (* n (fact (- n 1))
>> java.lang.Exception: Unable to resolve symbol: de in this context
>> user=> (def fact (n) ( cond ((= n 1) 1) (t (* n (fact (- n 1))
>> java.lang.Exception: Too many arguments to def
>> user=> (defn fact [n] (cond ((= n 1) 1)(t (* n (fact (- n 1))
>> java.lang.Exception: Unable to resolve symbol: t in this context
>> user=> (defn fact [n](cond ((= n 1) 1)(#t  (* n (fact (- n 1))
>> java.lang.Exception: No dispatch macro for: t
>> user=> (defn fact [n](cond ((= n 1) 1)(#true (* n (fact (- n 1))
>> java.lang.Exception: No dispatch macro for: t
>> user=> (defn fact [n] (cond ((= n 1) 1)(true (* n (fact (- n 1))
>> #'user/fact
>>
>> OK, what's with the funny square brackets? A sequence of forms
>> enclosed in square brackets is a vector, not a list. Why is the
>> arglist for a function a vector? For now let's accept that it is, and
>> pass on.
>>
>> user=> (fact 10)
>> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
>> clojure.lang.IFn
>>
>> OK, so that doesn't work. As Zaphod memorably put it, 'hey, what is
>> truth, man?' Good question:
>>
>> user=> (true? 'true)
>> true
>> user=> (true? true)
>> true
>> user=> (true? t)
>> java.lang.Exception: Unable to resolve symbol: t in this context
>> user=> (true? 't)
>> false
>> user=> (def t 'true)
>> #'user/t
>> user=> (true? t)
>> true
>>
>> OK, now we know the truth, surely we can write a valid fact?
>>
>> user=> (defn fact [n] (cond ((= n 1) 1)('true (* n (fact (- n 1))
>> #'user/fact
>> user=> (fact 10)
>> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
>> clojure.lang.IFn
>> user=> (defn fact [n] (cond ((= n 1) 1)((true? 'true) (* n (fact (- n
>> 1))
>> #'user/fact
>> user=> (fact 10)
>> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
>> clojure.lang.IFn
>>
>> OK, it looks like whatever's causing the break isn't the guard on the
>> second cond branch. Let's for a moment try something that's purely
>> boolean:
>>
>> user=> (defn band [l] (cond ((nil? l) true)((true? (car l))(band (cdr
>> l)
>> java.lang.Exception: Unable to resolve symbol: cdr in this context
>>
>> No CDR? It's LISP, but it can't fetch the contents of the decrement
>> register? fifty years of LISP history tossed into the dirt. So if the
>> CDR isn't called the CDR, what is it called (and what's the CDADR
>> called)?
>>
>> user=> (defn band [l] (cond ((nil? l) true)((true? (first l))(band
>> (rest l)
>> #'user/band
>> user=> (band '(true true true))
>> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
>> clojure.lang.IFn
>>
>> OK, can we write any function at all that works?
>>
>> user=> (defn square [n] (* n n))
>> #'user/square
>> user=> (square 4)
>> 16
>>
>> Fine, so recurse up from that:
>>
>> user=> (defn power [n m] (cond ((= m 0) 1)(true (* n (power n (- m
>> 1))
>> #'user/power
>> user=> (power 2 2)
>> java.lang.ClassCastException: java.lang.Boolean cannot be cast to
>> clojure.lang.IFn
>>
>> Aggghhh...
>>
>> Getting LISP to work seamlessly inside a Java environment with easy
>> intercalling between LISP and Java is a very big win, and potentially
>> knocks things like JScheme and Armed Bear Common L