#clojure logs

2008-06-08

14:50Lau_of_DKAny functional-p guru here, who can tell me if there's some neat way to do a prime factorization of x ?
15:26slavaLau_of_DK: asymtotically, all algorithms are exponential-time
15:26slavahi WardCunningham
15:27WardCunninghamhello slava
15:27slavaif you're _that_ WardCunningham, I spent much time browsing through the c2 wiki back in the day. it was quite educational when I was getting into the whole "languages other than Java" thing. :)
15:28WardCunninghamYes, that is my site. Thanks for the kind words.
15:29WardCunninghamAre you a clojure geek now? Or just looking around like me?
15:29slavai think clojure is really neat. i don't see myself using it for projects any time soon, but it has a lot of good ideas and I like to learn new languages
15:30WardCunninghamagree.
15:30slavain particular, its approach to immutability and concurrency strikes me as the Right Thing.
15:31slavayou can still have mutable state, but the library gives you top-notch persistent collections.
15:31WardCunningham and stm.
15:31slavaand as far as concurrency goes, you get STM and message passing.
15:32slavayup.
15:32Lau_of_DKslava, Cloure is the right thing, resistance is futile
15:33slavaas far as collections go, persistent collections probably work fine in most cases. I think you still need mutable specialized arrays for numerics
15:34slavahmm. if the only mutable arrays are those specialized to hold a single numeric type, you avoid co-variance/contra-variance issues in the type system.
15:34rhickeyLau_of_DK: please no fighting or taunting here
15:34Lau_of_DKrhickey, dont worry, Im a man of peace
15:34rhickeyClojure has typed access to Java arrays of primitives
15:34slavadoes all the seq stuff work there?
15:35rhickeyyup, but with boxing overhead
15:35slavahow far are you going to go with compiler optimizations?
15:35WardCunninghamslava: nice to meet you. I'm going back to just lurking ... saving my wrists for work.
15:35rhickeythere's also higher-level but super-efficient whole-array transforming macros like amap and areduce
15:35slavaif you implement some analysis you can avoid creating the iterator if its entirely consumed without being returned or used for its object identity
15:36slavarhickey: right; i'm suggesting that you can implemenet map, reduce etc gnerally using seqs and optimize the case where the seq is iterating over a known type
15:36slavadepends on how much effort you want to put into the compiler, of course
15:36rhickeyI might do that at some point, but there are lots of issues, as the 'mapped' function must be typed as well
15:37rhickeyamap and areduce are functional
15:37rhickeyi.e. return new arrays
15:37slavai don't think the mapped function must be typed; it doesn't see the iterator directly, does it?
15:37rhickeyI'd like to avoid devolving into Java-like typing
15:38rhickeyall fns take/return Objects
15:38slavai'm suggesting something more along the lines of inference, not declaration.
15:38slavaif the fn is small, you can inline it and avoid the boxing at the procedure call boundary
15:39rhickeyI understand, a lot of work
15:39slavayup :)
15:39rhickeyRight now I'm getting terrific optimizations for free from HotSpot
15:39slavaless work than writing a native compiler, though. once you get past the high-level optimizations, you get the rest from hotspot.
15:40rhickeyright
15:40rhickeyand they might do the boxing elimination for me at some point too
15:40slavamight :)
15:41slavai think in general, boxing elimination is hard on the jvm unless you have specific knowledge
15:41slavathere are too many ways to 'observe' the identity of an object
15:41rhickeyI've added enough so that people who have to do number crunching don't have to leave Clojure. Other optimizations are premature for me right now.
15:42slavaare you using/going to use clojure for commercial projects?
15:43rhickeystarting to
15:43slavanice
15:44slavaclojure seems really well designed. have you spent a lot of time working with scheme and cl in the past?
15:44rhickeyCL
15:46rhickeyIn many ways Clojure is a challenge to Lisps to change
15:47slavayeah, CL is pretty stagnant. I worry that in 10 years, it will be mostly forgotten, which is a real shame because it has features you don't see in many languages (multiple dispatch, MOP, setf, procedural macros)
15:47rhickeyit is a treasure-trove of ideas
15:47slavaseeing your efficient persistent collections made me realize that the destructive list operations are mostly obsolete
15:48slavabecause in CL, you cannot assume they have side effets; they're purely for optimization
15:48slavaand in general, why did you decide to keep cons cells around? is it because they map trivially to the seq protocol?
15:48slavait seems that in most cases persistent vectors can replace them
15:49rhickeyconsing at the front is useful, but yes, in practice vectors get a lot more use, at least in idiomatic Clojure code
15:49rhickeylists reserved mode for code
15:49rhickeymore
15:50slavais it possible to make persistent vectors efficient for consing on the front? it seems like you could add a 'head' slot that works like 'tail', but i'm not sure if the tree rebalancing gets hairy
15:50slavai haven't thought about this before
15:50rhickeyyou could use the vectors backwards as lists
15:50slavaah, true
15:51rhickeyboth support a 'stack' protocol where you ignore the order
15:52rhickeyusing vectors for data and lists for code gives a nice separation vs Lisps where you use lists for both
15:52slavaoh, i didn't find this in the code: how is append implemented on persistent vectors?
15:52rhickeyconj adds to end of a vector
15:52slavai've found that having separate sequence types for code and data is nice too. it can catch mistakes and makes code easier to understand -- you know what the resulting sequence will be used for
15:52slavaappending two persistent vectors, though
15:53rhickeynot supported directly
15:53rhickeybasically O(n) add one to the other
15:53slavai wonder if there's a way to do that more efficiently knowing the structure of persistent vectors
15:54slavait would still be o(n), just a constant speedup
15:54rhickeyif the first was a multiple of 32 in size, easy
15:55slavayup
15:58slavai just realized that one can implement a persistent-vector with double ended consing as a pair of persistent vectors :)
15:59rhickeyThere's a PersistentQueue in the Clojure lib, not yet exposed in the API
16:03slavai see a potential problem there in that popped entries won't be GC'd until the entire queue is empty
16:04slavaunless RT.seq(r) converts the vector to a cons list
16:12rhickeyYou can't do that and preserve persistency
16:12rhickeyretention of the vector depends on push/pop patterns
16:13slavathat's what i meant; if you don't hold on to the old version of the queue, the values might not be GC'd anyway
16:13slavanot sure if that's a problem with the way this code is used
16:13slavaif you expose it to the user it will be something to address though
16:15rhickeyif someone allows n items to be pushed before consuming any, nothing implies they ought to be GC'ed prior to n pops
16:15rhickeyThere are dual-list based queues with amortized persistency
16:16rhickeyMy queue is not amortized since seq of the vector is O(1)
16:17slavayup
16:17rhickeyvariant on Okasaki's
16:17rhickeyenabled by persistent vectors
16:23Lau_of_DKIve never used VIM but I noticed that there's a clojure plugin for it on the wiki. Does it have the features that emacs have like repl interaction, autocomplete, all that stuff?
16:45Lau_of_DKGuess VIM doesn't have much of a user-core in here
16:46rsynnottis there an emacs repl for clojure?
16:47Lau_of_DKyea, you can connect to slime and get a REPL directly in emacs, if thats what you mean
16:53rsynnottah, there's slime for clojure?
16:54Lau_of_DKWell, there's a swank-clojure package
16:54rsynnott(I havn't really used clojure as yet; I'm more of a CL persn. It looks interesting, though)
16:54rsynnottah, cool, may give that a go
16:54rsynnottmain thing putting me off was percieved lack of a proper ide
16:54Lau_of_DKYea, want me to find a link for you ?
16:54Lau_of_DKHave you ever tried some of the Eulers ?
16:54rsynnottgot it
16:56Lau_of_DKI re-did some of the Eulers in clojure, just to try and get that functional feel, it was fun - and most effective
16:57Lau_of_DKYou can also check this out, just to see an easy little simulation with a GUI. http://ubuntuforums.org/showpost.php?p=5123892&postcount=16
16:57Lau_of_DKRich did something similar, his is better, but also a little bit more complicated
17:25Lau_of_DKrhickey, are there any tools to help setup more complex GUIs, or does it have to be done manually ?
17:26rhickeySome people are using Netbeans' Matisse to build a GUI they drive with Clojure
17:28Lau_of_DKHow do they import it, so as to drive it ?