#clojure logs

2008-05-25

09:22blackdogam 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
09:24blackdogcos i'm getting java.lang.ClassCastException: clojure.lang.IteratorSeq cannot be cast to clojure.lang.IFn
09:55rhickeywhat are you doing with *command-line-args*? That's a sequence of args, not a function
09:55rhickeye.g. the script:
09:55rhickey(println *command-line-args*)
09:55rhickey(flush)
09:55rhickeyprints: (hello)
10:27blackdogduh, thanks that works :)
10:27rhickeynp
10:29blackdogrhickey, 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:29rhickeygreat
16:20dabdhi all
16:20rhickeyhi
16:21dabdplaying with clojure at the repl I found this behavior that I don't understand
16:21dabd(lazy-cons 1 (list))
16:22dabdreturns (1 nil)
16:22dabdbut (cons 1 (list)) returns (1)
16:23dabdI'm using clojure compiled from source boot.clj SVN 874
16:33rhickeythe 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:34rhickeyi.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:34abrooksI thought a list was its own seq.
16:35rhickeyexcept for (), I have to fix that
16:36abrooksAh, I see.
16:36rhickeythat is also an implementation detail, proper use of collections should call seq
16:36rhickeyso you could swap a vector and it would still work
16:36rhickeylist is not a privileged collection in Clojure
16:36rhickeyjust one of many
16:39dabdso in the examples I typed the compiler should issue an error?
16:45rhickeyruntime error
17:04dabdthanks. I have one more question
17:05rhickeyok
17:05dabdI find the fibonacci example in the wiki book a little bit harder to understand than the classic haskell one liner
17:05dabdfiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist))
17:06dabdI tried to write a similar version in clojure but I couldn't
17:06lisppaste8dabd pasted "fib" at http://paste.lisp.org/display/61250
17:07dabdis it possible to write something similar in clojure with the lazy operators?
17:08Chouserdabd: looks ok to me
17:09Chouser(take 10 (fib)) ;==> (0 1 1 2 3 5 8 13 21 34)
17:10dabdok I forgot to use 'take'
17:10dabd:-)
17:15dabdanyway my version is very inefficient
17:35Chouser(def fib (list* 0 1 ((fn step [a b] (lazy-cons (+ a b) (step b (+ a b)))) 0 1)))
17:36Chouser...because what we really need is more implementations of fib.
17:56jbalintHi
17:56ChouserHi
17:57jbalinti'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:57Chousersorry, I've never tried clojure in emacs. Anyone else here have an idea?
17:57jbalintwhat do you use for editing
17:58Chouserusually just vim
17:58jbalintah
17:58ChouserI've started trying to use enclojure in NetBeans, but it's not quite ready "enough" for me.
18:00jbalintwhats kind of stuff are you working on with clojure
18:00Chouserhttp://clojure-log.n01se.net/ is generated by clojure code
18:01jbalintis it from your filesystem, or a bot?
18:02ChouserI 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:02dudleyfjbalint: I've had better luck with the slime mode, even though it's pretty young
18:02Chouserfor the irc log, it just reads a text file generated by irssi
18:02jbalintdudleyf: thanks, i'll give it a look
18:03jbalintChouser: I see, cool
18:03jbalintis it possible to compile to a class file?
18:03jbalintthe only thing i found was proxy , but its only sensible at runtime
18:03Chouserif you need to define a new class, you can use gen-and-save-class
18:04jbalintgreat, where is that documented?
18:04Chouserbut that's really just for java interop. The implementation will still be in a .clj file.
18:04ChouserYou can pack .clj's into a .jar and have the runtime find them there.
18:04jbalintis there a special classloader?
18:05Chousergen-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:05jbalintok
18:07ChouserI 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:08jbalintbut 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:09Chouserwhy do you need to load classes?
18:09jbalinti dont know? a thousand reasons. this is how java works
18:09ChouserI believe you, there are just different reasons with different solutions.
18:10jbalintthe most obvious need would be using clj classes with some framework that you pass in a class name
18:10jbalintit would load the class, without needing some special "support" for clojure
18:10Chouser(gen-and-load-class) allows you to produce a new named class at runtime, which you can then pass to an extrnal framework.
18:11dudleyfBut that just makes a "shell" object that uses Clojure functions as methods
18:11jbalintyes, thats fine
18:12ChouserI believe servlets need the path to a .class file. You can use (gen-and-save-class) to generate such a class file.
18:12jbalintsee, there's another example :)
18:12ChouserIf something needs you to pass in an instance of class derived from some specific base class, (proxy) may be all you need.
18:12jbalintyeah, i've been looking at that
18:13jbalintgen-and-save-class must be quite similar?
18:13ChouserSo, as I said, it depends on what you actually need.
18:13jbalintbesides the output of course
18:14Chouserno, gen-and-*-class are pretty different from proxy.
18:14jbalintwell, i just need general classloading compatibility with java
18:14Chouserproxy is simpler, if you can get away with it.
18:14jbalintyes, sorry. i mean from the args point of view.
18:14jbalintalthough, what is the difference?
18:15jbalintproxy will need to generate a class, just goes into a classloade rinstead of a file
18:15Chouserproxy 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:16jbalintah
18:16ChouserBut gen-and-*-class create named final classes, so you can't change them once you load them.
18:16Chouserto reduce the pain that causes, they split of the class definition from the implementation, which makes them a bit more complicated to use.
18:17jbalintok, sounds painful :p
18:18Chouserwell, it's not too bad. But you still want to use proxy if you can.
18:19ChouserYou 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.