I hope you are either 14 years old, or joking.  Rather than sitting down 
and attempting to conjure up perfect lines of a new programming language 
you have never used before, it might be good to spend some time reading! 
  Learning new things is good for your brain, and I can promise you 
Clojure will be especially good.   By the extreme laziness displayed in 
your email, maybe you would prefer watching the movies at 
http://clojure.blip.tv rather than reading documentation to get started, 
but it will be inevitable so you might as well dig in.  Just start at 
the top left of the homepage with rationale, and work your way down. 
You will not only be able to write some experiments that will be less 
frustrating, but you will also learn some pretty cool new stuff, one of 
the most profound being Clojure's pervasive support for concurrency. 
After that you should start reading code, lots of it.

-Jeff

Simon Brooke 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 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
> 
> Arrrrggghhh...
> 
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to