#clojure log - May 25 2008

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

9:22 blackdog: am i correct in thinking that anything after the -- should be sent into *command-line-args*, in java -cp $CP clojure.lang.Script $comm.clj -- hello

9:24 cos i'm getting java.lang.ClassCastException: clojure.lang.IteratorSeq cannot be cast to clojure.lang.IFn

9:55 rhickey: what are you doing with *command-line-args*? That's a sequence of args, not a function

9:55 e.g. the script:

9:55 (println *command-line-args*)

9:55 (flush)

9:55 prints: (hello)

10:27 blackdog: duh, thanks that works :)

10:27 rhickey: np

10:29 blackdog: rhickey, really enjoying clojure, just using it for scripting purposes right now while i learn lispish ways but i think you're onto a winner

10:29 rhickey: great

16:20 dabd: hi all

16:20 rhickey: hi

16:21 dabd: playing with clojure at the repl I found this behavior that I don't understand

16:21 (lazy-cons 1 (list))

16:22 returns (1 nil)

16:22 but (cons 1 (list)) returns (1)

16:23 I'm using clojure compiled from source boot.clj SVN 874

16:33 rhickey: the second arg to cons/lazy-cons must be a seq. Unfortunately, () and (list) are testing true for (seq? ) when they shouldn't. It should be (cons (seq (list))), just like it should be (cons (seq []))

16:34 i.e. in clojure there's no such thing as a empty seq, either there is a seq with a first, or there is no seq - nil

16:34 abrooks: I thought a list was its own seq.

16:35 rhickey: except for (), I have to fix that

16:36 abrooks: Ah, I see.

16:36 rhickey: that is also an implementation detail, proper use of collections should call seq

16:36 so you could swap a vector and it would still work

16:36 list is not a privileged collection in Clojure

16:36 just one of many

16:39 dabd: so in the examples I typed the compiler should issue an error?

16:45 rhickey: runtime error

17:04 dabd: thanks. I have one more question

17:05 rhickey: ok

17:05 dabd: I find the fibonacci example in the wiki book a little bit harder to understand than the classic haskell one liner

17:05 fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist))

17:06 I tried to write a similar version in clojure but I couldn't

17:06 lisppaste8: dabd pasted "fib" at http://paste.lisp.org/display/61250

17:07 dabd: is it possible to write something similar in clojure with the lazy operators?

17:08 Chouser: dabd: looks ok to me

17:09 (take 10 (fib)) ;==> (0 1 1 2 3 5 8 13 21 34)

17:10 dabd: ok I forgot to use 'take'

17:10 :-)

17:15 anyway my version is very inefficient

17:35 Chouser: (def fib (list* 0 1 ((fn step [a b] (lazy-cons (+ a b) (step b (+ a b)))) 0 1)))

17:36 ...because what we really need is more implementations of fib.

17:56 jbalint: Hi

17:56 Chouser: Hi

17:57 jbalint: i'm having a problem with the clojure emacs mode calling switch-to-lisp (when loading a file), but its opening the comint in the same window my file is in, but i already have it open it another window. any idea why this is happening or how to fix it?

17:57 Chouser: sorry, I've never tried clojure in emacs. Anyone else here have an idea?

17:57 jbalint: what do you use for editing

17:58 Chouser: usually just vim

17:58 jbalint: ah

17:58 Chouser: I've started trying to use enclojure in NetBeans, but it's not quite ready "enough" for me.

18:00 jbalint: whats kind of stuff are you working on with clojure

18:00 Chouser: http://clojure-log.n01se.net/ is generated by clojure code

18:01 jbalint: is it from your filesystem, or a bot?

18:02 Chouser: I also have a thing that pokes around on real estate sites and sends me an email summary of resent changes to properties that match my criteria.

18:02 dudleyf: jbalint: I've had better luck with the slime mode, even though it's pretty young

18:02 Chouser: for the irc log, it just reads a text file generated by irssi

18:02 jbalint: dudleyf: thanks, i'll give it a look

18:03 Chouser: I see, cool

18:03 is it possible to compile to a class file?

18:03 the only thing i found was proxy , but its only sensible at runtime

18:03 Chouser: if you need to define a new class, you can use gen-and-save-class

18:04 jbalint: great, where is that documented?

18:04 Chouser: but that's really just for java interop. The implementation will still be in a .clj file.

18:04 You can pack .clj's into a .jar and have the runtime find them there.

18:04 jbalint: is there a special classloader?

18:05 Chouser: gen-and-*-class is pretty new, not in the release. If you get the svn version, there are some docs and examples in the code.

18:05 jbalint: ok

18:07 Chouser: I belive Clojure uses it's own special classloader, yes. But I think that has more to do with how every expression is compiled on the spot and then loaded, more than anything to do with finding .clj files.

18:08 jbalint: but i need to be able to load classes, like java. so either i need a compiled classfile or a classloader that reads the cljs

18:09 Chouser: why do you need to load classes?

18:09 jbalint: i dont know? a thousand reasons. this is how java works

18:09 Chouser: I believe you, there are just different reasons with different solutions.

18:10 jbalint: the most obvious need would be using clj classes with some framework that you pass in a class name

18:10 it would load the class, without needing some special "support" for clojure

18:10 Chouser: (gen-and-load-class) allows you to produce a new named class at runtime, which you can then pass to an extrnal framework.

18:11 dudleyf: But that just makes a "shell" object that uses Clojure functions as methods

18:11 jbalint: yes, thats fine

18:12 Chouser: I believe servlets need the path to a .class file. You can use (gen-and-save-class) to generate such a class file.

18:12 jbalint: see, there's another example :)

18:12 Chouser: If something needs you to pass in an instance of class derived from some specific base class, (proxy) may be all you need.

18:12 jbalint: yeah, i've been looking at that

18:13 gen-and-save-class must be quite similar?

18:13 Chouser: So, as I said, it depends on what you actually need.

18:13 jbalint: besides the output of course

18:14 Chouser: no, gen-and-*-class are pretty different from proxy.

18:14 jbalint: well, i just need general classloading compatibility with java

18:14 Chouser: proxy is simpler, if you can get away with it.

18:14 jbalint: yes, sorry. i mean from the args point of view.

18:14 although, what is the difference?

18:15 proxy will need to generate a class, just goes into a classloade rinstead of a file

18:15 Chouser: proxy creates an anonymous class and an instance in-line. It's very easy to close around whatever data you need. And you can change your code and re-run it no problem.

18:16 jbalint: ah

18:16 Chouser: But gen-and-*-class create named final classes, so you can't change them once you load them.

18:16 to reduce the pain that causes, they split of the class definition from the implementation, which makes them a bit more complicated to use.

18:17 jbalint: ok, sounds painful :p

18:18 Chouser: well, it's not too bad. But you still want to use proxy if you can.

18:19 You can generally use proxy unless you need to call your super-class, or override something private or protected. There may be other restrictions I'm not thinking of.

Logging service provided by n01se.net