#clojure logs

2008-02-12

11:37ChouserI guess neither recur nor thisfn do what I want from inside a lazy-cons
11:38rhickeyif you are on the latest SVN you can name your fn like this: (fn name [args]... (lazy-cons x (name ...
11:39rhickeyas described here: http://groups.google.com/group/clojure/msg/afb8809c741567bc
11:54Chouserah, cool. Well, my function was already named via defn, so I could use its name.
11:54ChouserI just thought recur would be more correct before I realized that it didn't really make sense for lazy-cons
11:55rhickeyright, and thisfn didn't nest, so it had to go
11:55Chouserso then I tried thisfn, thinking that was still "more correct" than refering to my own function by name. That gave me a difficult to understand error.
11:55Chouserwrong number of params.
11:56ChouserI suppose thisfn was refering to a func built by the lazy-cons macro? Anyway, it took me a while to figure that out.
11:56ChouserSo now I'm back to the obvious solution that I had at first. ;-)
11:59rhickeythat's good, sorry for the confusion
12:00Chouserno need to apologize. If I had any better idea how I thought it should work, I would suggest it. But I've got nothin'
12:00ChouserUnless... hm, is there any way the "wrong number of args passed" error could give the name of the function you're actually calling?
12:01Chouser...if it's named.
12:01Chouseror maybe the list of formal parameters? ...except of course there are many such lists for each fn.
12:01ChouserWell, nm.
12:01ChouserLike I said, I've got nothin'
12:02rhickeythe name might be possible, I'll look into it
12:03ChouserIt's very good to have the line number of the .clj file in the stack trace. Dunno how hard that was, but it sure helps a lot.
12:05rhickeyClojure emits real debug info - I wish more of the Java debuggers could deal with non-java files
12:06ChouserI think that's a problem with the whole IDE mentality... Giant stacks of code and tools all assuming some particular source language.
12:07ChouserMaybe one day when we have the perfect language such effort will be justified. But for now I think it just helps lock people into old languages.
12:08rhickeybut these days they know it could at least be JSP or Javascript, yet each gets special-cased...
12:08Chouserrhickey: have you looked at arc at all? I'm a bit curious what you think of its goals, syntax decisions, etc.
12:09rhickeyI'm very envious of the attention it gets, but haven't looked at the language in detail. On the surface it seems to have a lot less going for it than Clojure ;)
12:11Chouserheh. yeah. If you'd published a couple popular books (and maybe made a million dollars) first, I bet clojure would get more attention.
12:11rhickeyI'm working on it
12:11Chouserbut I tend to agree. I wouldn't claim to know much about lisps, but I wrote a couple projecteuler solutions in arc, and was a bit disappointed.
12:12ChouserI like some of the conventions that it has, but I can whip up a couple macros to give me that in clojure, and then I still get access to Java libs, namespaces, etc.
12:13ChouserI like arc's (if) ... the power of (cond) with the simplicity of CL (if)
12:15rhickeyI think other things are much more important - especially abstractions for the core data types
12:15Chouseryes, I agree.
12:16Chouserlike I said, if I want arc's (if) bad enough, I can write a pretty simple macro in clojure to get it (although any other clojure user might be annoyed while reading my code).
12:16rhickeyClojure cond is pretty lean already
12:17Chouserbut trying to write macros in arc to get abstract data structures would be a *huge* pain, even if it were possible.
12:18ChouserI played with scala a bit before picking up clojure, and the similarities and differences are interesting.
12:18Chouserboth have data structure abstractions, but scala is much more "classical" in it's OO.
12:19ChouserI haven't done objects/classes/type tag stuff in clojure yet
12:20rhickeyClojure is much simpler than Scala
12:20ChouserScala comes with the kitchen sink pre-installed.
12:21ChouserBut of course it also has static typing -- I'm not sure which I prefer on the front.
12:21ChouserScala has no macros, which is a big strike against it.
12:25ChouserBut I can't say I like lisp's lack of syntax. Clojure's [vectors] help a little, but I guess nobody willing to invest a bunch of time in creating a lisp is likely to see a need for more syntax.
12:37Chouseroh! cond returns nil?
12:38ChouserI guess its nested ifs for me.
12:47rhickey? cond returns the value of the matching expr
12:48rhickeytakes an even number of args, this is not Arc :)
12:55Chouserhttp://clojure.sourceforge.net/reference/macros.html
12:55Chouser"(cond) returns nil"
12:56Chouseroh! And my problems was I was passing a list of lists of 2 items each.
13:02rhickeyright - Clojure doesn't need those extra parens
13:06Chousercool. What about that line in the docs? Did I misunderstand it, or is it incorrect?
13:08rhickeyI thought you meant cond always returns nil. Yes (cond) returns nil.
13:12Chouseroh! ha. ok, so I misused the macro, and then misread the docs.
13:12ericthorthere is a netbeans plugin and it's very easy to use
13:13ericthoroops...wrong room
15:13rhickeyinsvn - compiled regex literals #"pattern" - #"[0-9]+"
15:14rhickey(re-seq #"[0-9]+" "abs123def345ghi567") -> ("123" "345" "567")
15:15la_merrhickey: oooh, very nice :-D
15:15la_merDoes this mean reader macros are coming, or is this bolted into the runtime?
15:17rhickeyIt's a reader macro, but I still am not opening up the reader at this time
15:17rhickey(let [[a b] (re-matches #"([-+]?[0-9]+)/([0-9]+)" "22/7")]
15:17rhickey [a b])
15:17rhickey-> ["22" "7"]
15:18la_merFYI, I'm afraid that the eclipse plugin hasn't gotten much love over the past weeks. Work has been absolutely nuts.
15:18rhickeyhopefully the namespace stuff will help
15:20la_merThat's also nice. I would think it'd be ideal if the regex literal yielded a fn that returned an easily destructurable vector when passed a string to match against.
15:20la_merYeah, the namespaces will make everything a lot easier.
15:21la_merIt's just a matter of getting a few spare hours over a couple of weekends to mash everything together (and unwind the eclipse API's along the way).
15:22rhickeyI think hardwiring the vector might be limiting, useful sometimes but not others
15:22rhickeye.g. the sequence case
15:33Chousercould #"" return a regex object that also implements IFn?
15:34rhickeyThe problem is it would no longer be a Pattern for use by the rest of the Java API, as it is now (Pattern is final)
15:34ChouserAh. ok.
15:53Chouserhash- and sorted-maps are immutable?
15:55rhickeyyup
15:56Chouserso is there something better I should use for memoizing, where I'm going to be doing a lot of one-at-a-time inserts?
15:56ChouserOr do they perform ok for that.
15:58rhickeythey are very good, IMO. but java.util.concurrent.ConcurrentHashMap is still available - depends on the use case
15:58rhickeyThe compiler uses the persistent collections extensively
15:59rhickeyand if you ever need to snapshot or branch, nothing can compete
16:00Chouserright, I (am beginning to) understand the huge value of immutable data and how to work with it, but I really need to have fast inserts.
16:00ChouserI'll try with hash-map first and see how it goes.
16:02rhickeyI benchmarked against the Java collections a good bit, the Clojure collections are within striking distance, and sometimes the lookup of the hash-map is faster. By all means try to use them and let me know if it becomes the bottleneck.
16:03Chouserit must not copy the entire data set for each insert?
16:04rhickeythat's right
16:26Chouserturns out I only need a couple hundred inserts. plenty fast.
16:31rhickey(defn test-map [n]
16:31rhickey (loop [m {} i 0]
16:31rhickey (when (< i n)
16:31rhickey (recur (assoc m i i) (inc i)))))
16:32rhickeyuser=> (time (test-map 100000))
16:32rhickey"Elapsed time: 322.976 msecs"
16:33Chouser:-)
16:33Chousernow I just need to figure out why my algorithm is failing.
21:12ChouserCould I use defmulti to define my own data structure that implements ISeq or whatever?
21:13rhickeylook at bean in the latest boot.clj for an example of implementing IPersistentMap
21:14rhickeylazy-cons implements ISeq pretty easily
21:14Chouserok
21:14rhickeybut multimethods don't map to Java methods
21:18Chouser(implement ...) huh, ok.