#clojure logs

2009-05-16

02:35tsdhCan anyone enlighten me when `var?' is useful? It seems it's true only for the return value of a `def'. (var? (def foo 17)) ==> true, but (do (def foo 17) (var? 'foo)) ==> false.
02:41hoeck,(let [x #'fn] (var? x))
02:41clojurebottrue
02:42hoecktsdh: but I haven't used it in 'real' code so far
02:42hoecktsdh: maybe it's just for completeness sake, or to implement crazy macros ..
02:46tsdhWhat's #' for a reader macro?
02:47tsdhAh, Var-quote. Thanks, now I've gotten it.
02:50unlinkI wish lazy-seq were easier to type.
03:08unlinkWhat's the best way to memoize a lazy-seq? (memoize #(nth (my-seq) %))?
03:08unlink+)
03:08unlink*for efficient random access
03:13hoeckunlink: putting it in a vector??
03:19kliif you hold on to the head of a seq, I think it will memoize it
03:19klinot 100% sure
04:20RaynesWow, this is taking forever.
04:33vyRaynes: You should also try compiling Open Office. (Wine is a good candidate too.)
04:38Raynesvy: It's still going. o_o
04:38RaynesI can picture myself three days from now sitting her all starry eye'd while I watch the text fly in Bash.
04:50RaynesYay it's done!
08:16eeedoes clj have a concept of generic infinity?
08:17eeeno matter what type is being compared, it is always bigger?
08:31marklarHi I'm trying to set up emacs + slime on a new machine. I getting a ClassNotFoundException: swank.swank whether I do it manually or using the clojure-mode clojure-install. Has anyone encountered this before?
08:38eeei just use clojure-dev eclipse plugin
08:50achim_phi all! did anybody here try to define custom data structures in clojure? i'm playing around with a simple deque (http://gist.github.com/111147), which works with a custom set of ops, but i'm not sure how to best proceed if i wanted first/last/next/butlast to give sensible results
09:06liebkeachim_p: I've only written custom clojure data structures in java, implementing the ISeq interface. I suppose you could use gen-class to do the same in pure clojure.
10:16tmianyone working with compojure know sessions work (in recent compojure master branch)?
10:31meredyddtmi: Yeah
10:31meredyddtmi: You include the value of (session-set) or whatever in the return value
10:32meredyddThe way to think of it is that your handler code returns "what I want to happen in response to this request"
10:32meredyddthat includes content, headers, etc to return, as well as what changes to make to the session
10:33meredyddsorry - I mean (session-assoc) and friends
10:40tmimeredydd: ok, thanks, I'll give it a shot :)
11:56eeeany clojure-dev users in here?
13:09biillyhi. anyone know how to pass expressions to swank-clojure in .emacs?
13:10biillyof how to read some expressions as a file to pass to swank-clojure-init-files?
14:28dreishI wonder whether this is real: http://www.google.com/trends?q=clojure%2Cjruby%2Cjython&ctab=0&geo=all&date=ytd&sort=0
14:28dreishAnd if so, why?
14:28dreish(Referring to the sudden surge in Clojure searches in the last data point.)
14:29dreishBecause it went to 1.0, maybe?
14:30danlarkinhttp://www.google.com/trends?q=clojure%2Cruby%2Cpython&ctab=0&geo=all&date=ytd&sort=0
14:31dreishMan bites python. At 90, Ruby's fighting fit. Eric Idle adds an orchestra to Monty Python comedy.
14:32dreishNot really comparable.
14:32danlarkinmmmm
14:32danlarkinthat's news items though, but yeah I get it
14:34dreishI think the surge is from 1.0. Looking at the 30 days chart, it settles back down after early May, though still above where it was before.
15:00ChouserI've got a map that's in theory is acting as an identity -- it's got values like an open socket, a thread or two, etc. But many of the values will never change (like the socket and thread).
15:01ChouserSo, should I pass it around as a reference type, because it has identity, and then not need to use reference types for the mutable members?
15:01cp2ugh
15:01ChouserOr, should I pass it around as a map value, because it's largely immutable, and then have specific reference types for the mutable members?
15:02ChouserI've been doing the latter, I'm just not sure it's right.
15:02danlarkinreference type as in (ref )?
15:03danlarkinIf that's what you mean, I would put the whole map in a ref
15:03danlarkinIMO
15:03danlarkinbut I guess it's just personal preference
15:05ChouserI mean reference type as in ref, atom or agent
15:05kotarakas in IRef?
15:05ChouserUm.. yeah, I guess so.
15:06ChouserI also generally have a closure or two. If the "object" is an IRef, then I need to make sure I close over the IRef, not the values it contained originally.
15:07ChouserIf the "object" is immutable, then I can close over the values fine, but need to close over each of the internal IRefs as needed.
15:07Chouserhm.
15:21Lau_of_DKGood evening gents - Whats new in Clojureland?
15:24kotarakHi Lau.
15:24cp2;)
15:24cp2i havent dropped in over 5 minutes, this must be a good sign
15:29biillyhow come when i javadoc from my repl in emacs it hangs, but in the console script it launches the browser fine?
15:41cp2looks like a spoke too soon
15:42rhickeyChouser: could the closures take the value as an arg?
15:44biillyin repl-utils/javadoc, it uses "browse-url" which i know is an emacs command, is this in clojure.contrib as well?
15:44kotarakrhickey: did you read the thread about the latest ns macro changes on the list?
15:44kotarakI had problems with the anon fn there
15:44rhickeykotarak: yes, I'm working on that now
15:45kotarakok :)
15:45rhickeyI hae a workaround but would rather get the 'right thing' in there - which is unwrapping do at top level
15:55Chouserthe only closures I have so far are for Threads -- but anyway, they can only take the object if its an IRef
15:56Chouser(def new-obj [a] (let [b (LinkedBlockingQueue.)] {:t (Thread. #(work a b)) :a a :b c}))
15:56Chousershould be defn
15:58Chouser(defn new-obj2 [a] (let [obj (atom {:a a :b (LinkedBlockingQueue.)})] (swap! obj assoc :t (Thread. #(work2 obj))) obj))
15:58ChouserI guess that's the other option?
16:00ChouserI like how the obj produced by new-obj can't be messed with -- I can't replace the LBQ with something else, because work is dealing with it directly and the map's immutable
16:01Chouserwith new-obj2, I could swap in a new value for :a or :b, and depending on how work2 is written, it may or may not notice the change.
16:03Chouseror do I have that backwards, and being able to change it while running is actually a benefit?
16:19cadsis there a clojure script that takes options and arguments for stuff like loading extra jars?
16:21rhickeykotarak: try 1370
16:21kotarakk, just a sec
16:25stuhoodcads: to add jars, you add them to java's classpath. see http://clojure.org/repl_and_main
16:27cadsI have written a bash script that takes these arguments: clojure [-j= & jars] [script file]
16:28cadsit either runs a script with the or if the script argument is left blank, starts
16:28cadsoh, wait
16:28kotarakrhickey: two thumbs up. Seems to work. :) At least I didn't get a failure up to now.
16:28kotarakthanks for quick fix!
16:29cadsit'll start a repl if it has no script to run, but if you give it a script it also passes the remaining commandline arguments to the script
16:29clojurebothttp://www.pigdog.org/auto/mr_bads_list/shortcolumn/1914.html
16:34kotarakrhickey: yep, works now.
16:43cadsI love clojure, and how tiny it is
16:44dnolen_ditto.
16:44cadsI can leisurely skim its sourcecode and get a good feeling of how whatever I want to know about works
16:44kotarakNo 1000 page Spec. Phew...
16:47cadsdoes scheme have unicode yet?
16:52kotarakcads: dunno, I didn't follow R6RS...
17:20cadshey, I'd like to use a clojure script as part of a unix pipe, but I'm not entirely sure how it is that pipes are able to control the processes that generate the data so as not to have to queue data up
17:21kotarakJust read from the pipe. The producer is stopped as soon as the buffer is full.
17:22cadssay the producer is a clojure script writing stuff to standard io, then the whole java process is just stopped?
17:22kotarakHmmm... I think the thread writing to the output buffer is stopped. The rest probably goes on.
17:24cadsI'll have to test it
17:26cadsone last thing, for io stream output, I'd like to write a special print function for a datastructure containing 3d particles. But I'd like the function to be called print, and in fact it would be neat for the actual print function to be able to print these structures specially, mixed in with normal printing for other things
17:26cadscan I overload print like that?
17:27kotarakcads: (defmethod print-method :your-dispatch ...) should do the trick
17:27cadsis the dispatch method for print in clojure.core?
17:28kotarakcads: dispatch is type
17:35StartsWithKfyuryu: hi
18:01danlarkinCan't decide if I should return nil/error code or throw an exception when something goes wrong with this couchdb api
18:03Chouserboth!
18:03rsynnottpossibly best throw an exception; then the user can catch it and use error codes if they want to
18:03rsynnottthe other way round is slightly more awkward for the user, IMO
18:04danlarkinor use error-kit!!!
18:10danlarkinyeah returning nil isn't really working out for me, because first you have to check for nil, then you have to either check for the error code or result, blah
18:28quidnuncWhat should "swank-clojure-extra-classpaths" be set to in emacs? I'm having trouble setting it to anything non-nil (can't find swank.clj anymore).
18:46danlarkinChouser: first real use of error-kit... I love it :)
19:17Chouserdanlarkin: hah, great.
19:19danlarkinAlso looking at david nolen's spinoza, it's also really cool!
19:19Chouserthat's an object system, right?
19:20ChouserI think error-kit incorrectly contains parts of an object system. :-/
19:21danlarkinyeah, it's an object system, which is why I passed it over initially when I saw it on the ML
19:21clojurebotwhy not?
19:22danlarkinbut it integrates with multimethods "correctly" (IMO) and doesn't reinvent too much, it looks like
19:22danlarkinI think it might be just-enough of an object system
19:23ChouserI'm not sure what I think of "object systems" in clojure, but even if they're ok, I don't think having error-kit invent its own is acceptible.
19:24danlarkinobjects are just struct-maps
19:24danlarkinwith extra sauce on top, so it looks like you can take it or leave it
19:24Chousersure, but it's what you do with them that makes or breaks it.
19:24Chouserright
19:24danlarkin(I'm saying all this without having used it yet :) )
19:25Chouserwell, error-kit error objects are just maps, but they have types which have inheritence, and they have constructors, etc.
19:26ChouserIt seems likely to me either error-kit doesn't need all that, or that other things do.
19:27danlarkinsorry, do you mean "...doesn't need all that, and that other things also don't"?
19:29danlarkinif so, I sortof agree initially, but I haven't made up my mind yet
19:30danlarkinit's all degrees anyway, as long as it's turing complete you can do whatever you want anyway, it's just how convenient it is to work with
19:49tashafahello
19:49tashafaqq....
19:49tashafahow do i get the arglists of a function passed into another function
19:49tashafa>=?
19:49tashafa?
19:52ChouserI don't think there's any way to get that.
19:52ChouserYou can get the arglists of a ver defined using defn, but even that's not 100% reliable.
19:53tashafacool thanks
19:54tashafanow i have to figure out a workaround
19:58danlarkintashafa: what do you need to accomplish? maybe there's another way we can help you think of
20:02tashafasorr..im back
20:05tashafai have a library that takes a function from a user and applies to 3 or 2 arguments
20:05tashafai want the user to be able to provide a function with either 2 or 3 items in the arglist vector
20:06tashafaso i need to be able to tell how many arguments the function the user provides has
20:07tashafasorry let me rephrase that last sentence
20:07Chousera callback with an optional 3 arg
20:08danlarkinso if they pass in a two arg function, you take one code path, and if they pass in a 3 arg function you take another
20:08tashafayup
20:09tashafabut i dont want them to pass a function with optional args
20:10Chouseryeah, that seems very reasonable. Functions could provide a way to find out what numbers of args they could take, they just don't currently.
20:10dreishWhat about passing a function and a number?
20:11Chouserand it wouldn't be as simple as in some langages -- javascript provides a single arity int, and that just wouldn't cut it in Clojure.
20:11tashafaChouser: yeah it looks like so
20:11dreishor {:fn x :arity n}?
20:11danlarkinor try to call with 3 args and catch IllegalArgumentException, and then try with 2?
20:11tashafadreish: seems a little to hacky for me
20:11dreishtashafa: Why?
20:12Chouser(fn foo ([a] a) ([a b c] c) ([a b c d & e] d))
20:12dreishdanlarkin: Exceptions take a long time to construct.
20:13tashafabecause i'm trying to mimic how javascript
20:13tashafadreish^
20:13danlarkindreish: don't dismiss them flat out, though. maybe this isn't a critical code path
20:13tashafait isnt
20:13tashafathe exception route seems like the forerunner
20:13dreishYech.
20:13dreishThat's the hackiest possible route, but whatever floats your boat.
20:14tashafayeah but it hides the hack from the user
20:14danlarkintashafa: are you relying on the user not to pass you a function on one argument, 4, 2 with an optional.. etc?
20:16tashafaim hoping the user passes a function with any number of arguments
20:16tashafa*a function that takes any number of arguments
20:17quidnuncDo .clj files need to (manually) compiled to Java byte-code or is it enough to have it in the classpath?
20:17tashafabut i just need to know how many arguments the function uses
20:18danlarkinquidnunc: it's enough to have it in the classpath
20:18Chousertashafa: I think wanting to know that is reasonable, and this sounds like a solid use-case.
20:19tashafapython has this functionality i think
20:19tashafai need to look it up though
20:19ChouserI can imagine wanting to be able to pass in general-purpose functions and have your fn look at them and do the right thing.
20:20ChouserSo, you could certainly choose to pursue a feature request.
20:20quidnuncdanlarkin: Thanks.
20:20Chouser...but that's not going to help you today. For today you need to find an acceptible work-around
20:20dreishI can't think of any good reason IFn couldn't have a .getArities()
20:21Chouserdreish: returning a set? plus a flag to indicate variadic?
20:21dreishI'd think a set.
20:22tashafacool... i'll try and pursue a feature reauest and find a workaround. If i get anywhere i'll be sure to post back here
20:22Chouserone work-around would be a func that takes a 2-arg fn, and returns a 3-arg fn that ignores the 3rd arg
20:22Chouser(do-callback (fn [a b c] ...)) would just work.
20:22tashafaChouser: you are a genius
20:23Chouser(do-callback (fix-it (fn [a b] ...))) would also work.
20:30hiredmanI think .getArities would return a boolean IFn
20:31dreishHow would you iterate over that?
20:31hiredmandreish: I am just thinking it would make handling & rest easier
20:32dreishGood point.
20:33hiredmanhmmm
20:33hiredmanI guess it could be some subclass of set
20:35hiredmanthat allows you to specificy some rule, like (> x 3) for set membership
20:42hiredman~def c.l.PersistentHashSet
20:46danlarkinChouser: I can't call error-kit/raise with a sexp that returns the correct error because raise is a macro, so should I be using raise* for this?
20:52Chouserlooks right
20:53Chouserappears to even be documented.
20:53danlarkin'doh!
20:53danlarkinwhere, do you mean the docstring?
20:53Chouseryes, just that.
20:53hiredmanhmmmm
20:54ChouserI didn't mean to suggest you shouldn't have asked.
20:54hiredmanIPersistentSet does not have a seq method, but the repl seems to call seq on it when trying to print it out
20:55hiredmanjava.lang.UnsupportedOperationException: seq
20:55Chouser,(seq #{:a :b :c})
20:55clojurebot(:a :c :b)
20:55Chouser?
20:55hiredman~def c.l.IPersistentSet
20:55hiredmanif you proxy IPersistentSet, and try to print out the resulting object
20:55hiredman*boom*
20:57ChouserIt's just and interface. You have to provide all the functions if you want them to do anything.
20:57Chousers/and/an/
20:57Chouser(proxy [clojure.lang.IPersistentSet] [] (seq [] '(1 2 3)))
20:58hiredmanChouser: I don't want them to do anything
20:58hiredmanI don't want a seq method, the interface does not contain one, but when the repl tries to print out my proxy object it tries to call a seq method on the object
20:59hiredmanI imagine in some print function somewhere there is an IPersistentSet that should be an APersistentSet
21:00hiredman,(map #(.getName %) (.getMethods clojure.lang.IPersistentSet))
21:00clojurebot("disjoin" "get" "contains" "equiv" "count" "cons" "empty" "seq" "count")
21:00hiredmanhmmm
21:00hiredmanah
21:00hiredmanextends
21:00hiredmanof course
21:03danlarkinfor the records regarding error-kit and raise: yes I just ran macroexpand-1 on raise and substituted as necessary
21:03danlarkinChouser: so thanks :)
21:04Chouserheh, ok.
21:07danlarkinclojurebot: exceptions?
21:07clojurebothttp://paste.lisp.org/display/74305
21:07danlarkinclojurebot: thanks :)
21:07clojurebotPardon?
21:11hiredman~def clojure.set/union
21:12hiredmanthat reduce is a drag
21:16hiredmanI don't see how clojure.set/union can be made to work with rule defined sets
21:20hiredman~paste
21:20clojurebotlisppaste8, url
21:20lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
21:22lisppaste8hiredman pasted "rule set" at http://paste.lisp.org/display/80355
21:57unlinkIs there any way to access what type of struct a struct instance is?
22:01Chouserit's a map. that should be enough. :-)
22:01danlarkin_you can have a :type key
22:01danlarkin_and then call clojure.core/type on it
22:01danlarkin_if you must
22:02danlarkin_or at least I thought you could
22:02unlinkIt's in there as a private field `def`, so tantalizingly inaccessible...
22:02danlarkin_oh, :type key on the metadata
22:03unlinkuser=> (meta (struct a 1 2))
22:03unlinknil
22:03danlarkin_it doesn't put it there for you :)
22:05unlinkSo I can't access it?
22:06danlarkin_a struct-map is just an optimized map
22:06danlarkin_it isn't a special thing
22:07unlinkIt is a clojure.lang.PersistentStructMap
22:07unlinkWhich has knowledge of what struct type it is.
22:08danlarkin_implementation detail
22:09unlinkExcept for the fact that it might be useful to know what kind of struct you are.
22:09danlarkin_the point is that you shouldn't be trying to use structs like classes
22:10unlinkWhat's the right way to have a typed structure, then?
22:13danlarkin_put a :type key in the metadata
22:13hiredman(type #^{:type :foo} {:a 1})
22:13hiredman,(type #^{:type :foo} {:a 1})
22:13clojurebot:foo
22:17mattdwdoes anyone know if there's a way to provide class/interface names to 'proxy' at runtime?
22:18mattdwsay (defn mk-proxy [cls] (proxy [cls] [])) ?
22:19Chouserget-proxy-class
22:19Chouserinit-proxy
22:20mattdwah sweet
22:20mattdwso proxy is just a wrapper around those two?
22:21unlinkdanlarkin_: I found what I was looking for. clojure.contrib.types/deftype
22:22danlarkin_clojurebot: def deftype
22:34danlarkin_Hm. couchdb returns the same status code & error message when you try to access a database that doesn't exist and try to access a document that doesn't exist
22:34danlarkin_so (document-get "foo" "bar") doesn't know if it's the DB or document that doesn't exist... in its current incarnation, at least
22:35mattdwChouser: sweet, that's working great
23:07Chouserdoes anyone have a link for the blog that listed various ways to bundle data and functions in clojure?
23:07Chouserit talked about namespaces, mapfulls of closures, etc.
23:27cadshey chouser, you about?
23:27Chousera bit -- on the phone too
23:28cadscool, lemme know when you got a sec, want to ask about your work with jscript and c, wrt clojure
23:44danlarkin_aw darn, and I can't even have multimethods like get and list that'd work on a server and database map, because clojure.core already defines them.
23:50stuhooddanlarkin_: i thought namespaces handle that?
23:50danlarkin_stuhood: well all of clojure.core is refer'ed into the current namespace by default
23:51danlarkin_you can exclude specific functions and then write your own of the same name, but it breaks anyone use "use"ing your library
23:52stuhooddanlarkin_: gotcha... so they'd have to rename the functions themselves during (use) anyway
23:53danlarkin_yep :-/
23:57Chousercads: ok, anything quick? gotta run soon.