#clojure logs

2010-01-31

00:08pdkyou could fuse them and be a hireddawg
00:09abrooksdawgedman
00:09hiredman:P
00:09hiredmanI bring it up because I jost noticed kdawg_
01:44technomancyonly one feature left before Leiningen 1.1.0
01:44technomancywute
03:56noidihow can I create a double[][] in Clojure?
04:00_ato,(make-array Double/TYPE 10 10)
04:00clojurebot#<double[][] [[D@df090d>
04:00noidithanks!
04:48fholmdmiller2718: you the guy who's working on clojure-clr ?
05:15dr_df0hi everyone
05:19dr_df0is anybody here?
05:19dr_df0are annotations supported now in clojure 1.1.0
05:19dr_df0I would like to use jboss netty library, but it requires annotations
05:25_atono, they're not supported
05:27dr_df0do you know any other high performance socket server library for clojure?
05:27dr_df0socket-server from contrib is not suitable
05:27dr_df0since it creates thread for every connection
05:28_atoI'd just use NIO directly
05:29_atoI haven't heard of a clojure wrapper for it
05:29_atothere's a bunch of java NIO "frameworks" listed here: http://technfun.wordpress.com/2008/04/21/critique-of-java-nio-frameworks/
05:30_atobut they sound like overkill ;-)
05:30dr_df0+ato: thx
05:59AWizzArdMoin sys
08:02noidiis there something like assoc-in for conj?
08:02noidiI need to do this: {:foo [1 2 3]} --> {:foo [1 2 3 4]}
08:03noidiright now I'm tempted to make the value of :foo a ref just to make updating easier, but I know there must be a better way :)
08:04Chousukenoidi: updatein
08:05Chousukewith a dash :P
08:05Chousuke(doc update-in)
08:05clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
08:06noidithanks!
08:06noidithat's exactly what I was looking for
09:02AWizzArdrhickey: is there a better/more performant way to do (= ::MyDefType (type obj))?
09:03rhickeyAWizzArd: not really - why are you doing that?
09:05AWizzArdIt is for my Clojure DB system. It can automatically create indexes during insertion, and for deftyped things it groups them by their type.
09:05rhickeyok, but why would it reference a type tag explicitly like that?
09:07AWizzArdCause this can be the criteria for being taken into an index. The user can specify the criteria when to index something.
09:07AWizzArdAnd all objects one inserts that pass this test go into a specific index.
09:08AWizzArd(insert *db* obj) <-- this adds obj to all indexes for which obj pasess the index-predicate
09:09AWizzArdI just wanted to make sure that using = and type is the right thing.
09:09rhickeyit will work
09:09AWizzArdgood
09:09AWizzArdthanks
10:20the-kennysomnium: Does congomongo support mongo's modifiers? ($push $inc etc)
10:28rrc7czhas anyone implemented platform/plugin capabilities before?
11:22satous(doc assoc-in)
11:22clojurebot"([m [k & ks] v]); Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created."
11:22satous(source assoc-in)
11:26avarushi
13:54AWizzArdwhen I have a (deftype Foo [a b c]) and then (def x (Foo 10 20 30)), what name does have bar then? (bar x) ==> (:a :b :c)?
13:56rhickeyAWizzArd: if you want map stuff, specify IPersistentMap and then you'll get support for (keys x)
13:56rhickeyotherwise you have normal Java reflection of fields
13:56AWizzArdAh sure, easy enough. I could have answered this myself. Thanks.
14:10AWizzArdThough it could be nice if Clojure offered its own reflection tools. Maybe this will be easier with clj-in-clj.
14:19avaruswhat's a simple template library for clojure in your opinion?
14:20AWizzArdavarus: template as in "html"?
14:20avarusyep
14:20AWizzArddid you look at Compojure?
14:21avarusoh, yes, I am just looking at it :)
14:21AWizzArdgood choice
14:21avarusok :)
14:22avarusI just set it up and it was very easy but I just tried the hello world for now :)
14:22AWizzArdThis route makes sense.
14:29avarusthe documentation is limited I think
14:29AWizzArdIt is not optimal yet. The best thing is to start with the hello world and try to extend it a bit.
14:30AWizzArdThen the Google Group has code examples. There is a Wikibook with more examples.
14:31AWizzArdAnd a bit documentation you can find here: http://compojure.org/
14:31avarusya, I'm there :)
14:32avarusthe group seems to be full of info :)
14:32avarusthe google group
14:32AWizzArdCompojure learning goes likes this: read the examples, modify them, play around with them, get an impression what you want to do, try to do it, begin asking questions in the GG.
14:32avarus:)
14:33AWizzArdafter a few iterations Compojure will make very much sense. It is indeed pretty simple.
14:33avarusfine
14:37avaruscool, contrib has something for json :)
14:38qbgWhen I'm use `lein repl`, I can require my project, but when I using `lein swank`, I can't. What am I doing wrong?
14:41AWizzArdhi cg
15:08robwolfeqbg: "M-x swank-clojure-project" is probably what you need
15:09qbgI tried that and that also didn't work
15:09robwolfedo you have ":dev-dependencies [[leiningen/lein-swank "1.1.0"]])" in your project.clj?
15:09qbgYes
15:11Raynesrobwolfe: You don't need lein-swank in order to use swank-clojure-project.
15:12robwolfeRaynes: from swank-clojure.el "Note that you must have swank-clojure.jar in the lib/ directory"
15:12Raynesswank-clojure.jar isn't lein-swank.
15:13robwolfeRaynes: right, but I thought that lein-swank depends on it
15:14dnolenqbg: you probably need to compile lein-swank yourself. that's what I had to do to get it to work
15:14dnolenI believe that lein-swank in it's current release doesn't properly add the src to the classpath
15:14dnolenin the lein-swank directory
15:14dnolenlein uberjar
15:15dnolenthen replace the lein-swank jar in the lib folder of your leiningen repo (I 90% sure you need to be using lein from source for any of this to work)
15:22qbgI built it and replaced the old one. Now it doesn't complain about the ^ reader macro, but I still can't require my project
15:24robwolfeqbg: slime starts ok, but you can not require your project?
15:24qbgYes
15:25qbgIt is just a classpath problem
15:25robwolfewhat's the namespace of yoour project and how do you try to load it?
15:25qbgCurrently it is called paradigmm (yes, a dumb name)
15:26qbgI currently call (require 'paradigmm) from the REPL to load it
15:26qbgThis works just fine using lein repl
15:26robwolfeunder "src" directory "paradigm.clj" with "(ns paradigm)"?
15:26qbg(add-classpath also works for loading it, but is non-ideal for other reasons)
15:26qbgYes
15:27qbgThe project directory was created with lein new
15:27robwolfein "lib" do you see lein-swank-1.1.0.jar ?
15:29qbgyes
15:29robwolfehmm... it works for me just fine
15:30hiredmandon't use single segment namespaces
15:30hiredmanfoo.bar
15:31qbgYeah, I need to come up with a better namespace name anyways
15:32qbgMost of the code is under paradigmm.<something> currently though
15:32qbgHmm... If I remove lein-swank from leiningen's lib directory and the project's directory, and then run lein deps in the project directory, lein swank doesn't work, even though the lein-swank jar is copied to the project's lib directory
15:34robwolfeqbg: what error do you see?
15:34qbg"swank is not a task. Use "help" to list all tasks."
15:35robwolfeso you don't have lein-swank in project.clj dev-depdencies
15:35qbgBut in my project.clj: ":dev-dependencies [[leiningen/lein-swank "1.1.0"]]"
15:36robwolfetry "DEBUG=1 lein swank" and see if there is "lein-swank.jar"
15:38qbgThere is no lein-swank in the output, nor my project.
15:38robwolfeqbg: I hope you don't run "lein" script from Leinigen sources?
15:39robwolfeI mean I hope you copied this script to your "~/bin" for example
15:40qbgGrr...
15:40qbgRunning lein-stable works; I have the lein script from the leiningen checkout symlinked to my ~/bin directory
15:40robwolfewrong! :)
15:43qbgHmm, the readme for leiningen says under Hacking: "When that finishes, symlink bin/lein from your checkout to your path. This will make "lein" run from your checkout while "lein-stable" uses the jar self-installed in ~/.m2."
15:43qbgThis seems misleading then...
15:44robwolfeit's for hacking on Leiningen
15:45robwolfefor other projects just use lein-stable
15:47qbgThe Emacs Integration page on github seems to implies that you need to be hacking on leiningen to use it
15:49robwolfeyou just need "lein" script and "leiningen-standalone.jar" and that's it
15:49robwolfeand "clojure" of course ;)
15:50qbgThe documentation seems misleading then
15:50qbgBut now it works, so I'm happy
15:50qbgNow to subject myself to the pain of Swing...
15:55avarusgood night
16:04{aaron}hi, i had a question about clojure...what, if anything, does clojure do about non-pure functions? do these matter, or affect assumptions clojure makes? e.g. if i want to, say, list files in a directory...that is a non-pure function... do i need to tell clojure that somehow?
16:04thearthurI'm trying to start a vpn(n2n) process through java.Runtime.exec and when the process starts in java the ioctl fails with "device or resource busy" when it starts form the shell it works??
16:05hiredman{aaron}: nope
16:05thearthurhow does a process start by runtime.exec differ from a normal process
16:05{aaron}hiredman: so clojure doesn't cache results of functions, etc.?
16:06hiredman{aaron}: unless you use memoize
16:06{aaron}how about requirements for no side-effects in transactions?
16:06hiredman{aaron}: that is a practical requirement
16:06{aaron}that's my responsibility to ensure right?
16:06hiredmanyes
16:06{aaron}ok
16:07hiredmanyou can use the io! macro
16:07hiredman,(doc io!)
16:07clojurebot"([& body]); If an io! block occurs in a transaction, throws an IllegalStateException, else runs body in an implicit do. If the first expression in body is a literal string, will use that as the exception message."
16:07hiredmanbut io! doesn't seem to be used much
16:07{aaron}i see
16:07{aaron}well, i guess it depends on whether the side effects are significant
16:08{aaron}i guess it's not really an "effect"
16:08{aaron}if i'm logging the time in a transaction, then i can't ensure the time is always going to be the same each try
16:08hiredmandefinitely not
16:09hiredmanI think one possibility is to use an agent
16:09hiredmansends to agents inside a transaction don't happen until the transaction completes
16:10hiredmanI believe the docs for agents also specify side-effect free functions, but it is common to ignore that
16:10hiredman,(doc agent)
16:10clojurebot"([state] [state & options]); Creates and returns an agent with an initial value of state and zero or more options (in any order): :meta metadata-map :validator validate-fn If metadata-map is supplied, it will be come the metadata on the agent. validate-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn
16:10hiredmanhmm
16:10hiredman,(doc send)
16:10clojurebot"([a f & args]); Dispatch an action to an agent. Returns the agent immediately. Subsequently, in a thread from a thread pool, the state of the agent will be set to the value of: (apply action-fn state-of-agent args)"
16:10hiredmanI guess it doesn't specify that
16:13{aaron}i like the idea of be assured that functions can be side-effect free...but if there is no way to distinguish in the language...how do i know that mr. library author hasn't just implemented all of his library with the standard Java libraries and doesn't make guarantees about side-effects?
16:13hiredmanyou don't
16:14rsynnottin general, trusting that the library author is infallible is probably a bit over-optimistic :)
16:14{aaron}so then does programming functionally gain me anything? i'm only as pure as the code i rely on
16:14hiredmanclojure emphasizes functional style with immutable values, but does not enforce it
16:14{aaron}hmm
16:15{aaron}ok. in other languages i guess they enforce declaring side effects or something?
16:15rsynnott{aaron}: well, if the library author SAYS their functions are side-effect fre, you can trust them or not
16:15hiredman{aaron}: well, I am pretty sure the only one that does is haskell
16:15{aaron}i see
16:15rsynnottjust as when a glibc author says that function X won't segfault, you can trust them or not
16:15{aaron}right ;)
16:16Chousuke{aaron}: if the library author claims a function is pure, and it turns out not to be, file a bug :P
16:17{aaron}ok, another question - does clojure itself, separate from Java libraries, have the notion of side-effects...or does it just rely on the JVM for all IO?
16:17Chousukehiredman: doesn't haskell have UnsafePerformIO or something that allows you to override the type system? :/
16:17hiredmanChousuke: no idea
16:17ChousukeI guess that's just an extension
16:18hiredman{aaron}: "just" is prejudicial, clojure is deigned to be integrated with the jvm
16:19{aaron}well, i'm trying to determine whether programming "only" in clojure guarantees pure functions...or whether there are intrinsically non-pure functions in clojure
16:19Chousukethere are.
16:19{aaron}(because then anything that imported stuff outside of clojure could automatically be labelled "dirty/sideeffects"
16:19{aaron}ok.
16:19chouserprn
16:20chouserbuiltin function that prints to stdout -- a side-effect.
16:20Chousukebut the host is such an integral part of the language that it doesn't make sense to consider Clojure without one :)
16:20_ato{aaron}: one of the main philosophies of Clojure is that pure-functional code, while having nice properties, is not always sufficient in a practical language. It allows side-effects but provides mechanisms (refs, atoms, agents etc) for making them safer.
16:20Chousukeit doesn't have to be the JVM though, but I guess that will always be the "main" Clojure host
16:21{aaron}ok. i assume the culture is such that when something *has* to have side effects, clojure authors typically make this pretty clear
16:22Chousukehmm, well, you can use ! in naming :)
16:22Chousukehaphazardly mixing functional things and size effects just leads to bad code so it's implicitly discouraged :P
16:24{aaron}i see, that's what i was looking for
16:24_atoyep, usually it's either fairly clear from the context (eg you're doing IO or talking to a SQL database or something) or the ! naming convention is used.
16:25{aaron}cool
16:25ChousukeI think clojure actively tries to support a functional programming style rather than discourage any other style.
16:26Chousukebut a natural consequence is that imperative programming in clojure tends to feel out-of-place :/
16:26qbgWhen using lein swank, the system classloader doesn't have the project on the classpath, so where can I find a classloader that does?
16:27Chousukehmm, wasn't there some function to get Clojure's classloader? :/
16:28_ato(clojure.lang.RT/baseLoader) IIRC
16:32qbgYep, that works
17:30technomancyjust tagged a Leiningen 1.1.0 release candidate: http://github.com/technomancy/leiningen/blob/master/NEWS
17:31technomancywould love to get some more eyes on it before the release
17:31qedtechnomancy: grabbing it right now
17:31qedthanks! :)
18:29AWizzArdrhickey: Is there a principle possibility to make insertion into sorted-sets (or maps) faster? Something like "transient sorted-sets" into which I insert elements guaranteed in the correct order?
18:30AWizzArd,(let [x (range 300000)] (count x) (time (count (apply sorted-set-by < x))))
18:30clojurebot300000
18:30clojurebot"Elapsed time: 7320.944 msecs"
18:30AWizzArd,(let [x (range 300000)] (count x) (time (count (apply vector x))))
18:30clojurebot300000
18:30clojurebot"Elapsed time: 92.089 msecs"
18:33chouser,(let [x (range 300000)] (count x) (time (count (into [] x))))
18:34chouser,(let [x (range 300000)] (count x) (time (count (into [] x))))
18:34clojurebot300000
18:34clojurebot"Elapsed time: 163.705 msecs"
18:34chouser,(let [x (range 300000)] (count x) (time (count (into [] x))))
18:34clojurebot300000
18:34clojurebot"Elapsed time: 132.526 msecs"
18:35chouser,(let [x (range 300000)] (count x) (time (count (vec x))))
18:35clojurebot300000
18:35clojurebot"Elapsed time: 86.965 msecs"
18:35AWizzArdalso interesting
18:35AWizzArdvec and vector use transients under the hood i guess
18:35hiredmanI doubt it
18:36hiredmanI imagine they use to-array under the hood
18:46mecolinhello
18:46chouserhi
18:47mecolini have these two snippets http://pastie.org/803512
18:47mecolinhow can i make the second snippet to evaluate in the first one ?
18:49RaynesThere are a couple of pastebins that do Clojure highlighting specifically, including gist.github.com, paste.pocoo.org, ideone.com (also evaluates your code for you), and I think snipt.org does as well.
18:49RaynesNot that it matters all that much. Just sayin'. :)
18:49chouserwhat's read-file? but perhaps that doesn't matter -- you were hoping for the locals 'meta' and 'content' to be available to the code you're eval'ing?
18:49mecolinRaynes: thanks ;)
18:50mecolinchouser: I'd like to start off with snippet 2 to evalute in place of (eval tempalte)
18:51chouserhave you tried 'load-file'?
18:52mecolinchouser: next, I'd like decorate it with content and meta data
18:52mecolinchouser: with 'load-file' i cannot achieve it, can i ?
18:52chousercorrect, you cannot.
18:52chousernor with eval the way you're going about it.
18:53mecolincan you give some clue how should i proceed ?
18:53mecolins/give/give me
18:53chouserI think you'd have to read in the file and wrap it in (let [...] ...), then eval that let form.
18:53chouser,(eval (read-string "(+ 10 foo)"))
18:53clojurebotDENIED
18:54chouserbah. anyway, that fails because foo is undefined
18:54mecolinok
18:54chouserbut this fails the same way: (let [foo 5] (eval (read-string "(+ 10 foo)")))
18:55chouserthis returns 15: (eval `(let [~'foo 5] ~(read-string "(+ 10 foo)")))
18:55mecolinchouser: thanks !
18:55chouserhm. you might have other problems though if the file you're reading in is doing 'ns' or 'in-ns'
18:56mecolinin fact, i'm doing it in the 2nd snippet
18:58chouseryes you are. trouble.
19:06mecolinchouser: if i defined a function in 2nd snippet (let's say: defn template), is there a way to switch different layouts in 1st snippet using :use but within render-template ?
20:09qedeeneeeeasd
20:14ag90Hi. Does the Class/StaticField form work for static enums?
20:16ag90I'm trying to access java.awt.TrayIcon.MessageType but it complains about not being able to find the class. I have improted (java.awt TrayIcon) but none of the following work:
20:16ag90TrayIcon/MessageType/INFO
20:16ag90TrayIcon.MessageType/INFO
20:18arbschtjava.awt.TrayIcon$MessageType/INFO
20:18ag90Oh great that works.
20:18ag90Thanks
20:40konrGuys, why is this false?
20:40konr,(= "44" (reverse "44"))
20:40clojurebotfalse
20:40hiredman,(reverse "44")
20:40clojurebot(\4 \4)
20:41hiredman,(= "44" '(\4 \4))
20:41clojurebotfalse
20:41hiredmangood?
20:41konryes! thanks!
20:43konrthe correct would be, then
20:43konr,(= "44" (reduce str (reverse "44")))
20:43clojurebottrue
20:43hiredmanapply str, not reduce
20:43konrWhy?
20:43clojurebotwhy not?
20:43hiredmanclojurebot: deep
20:43clojurebotIt's greek to me.
20:44hiredmanstr uses a StringBuilder internally for multiple args (the apply case), the reduce case produces more intermediate garbage
20:49ts00000anyone here with some clojureql clue?
21:38jcromartiewould it make any reasonable sense to use a set with vectors as keys for two-dimensional data?
21:39jcromartiesorry, hash-map, not set
21:40jcromartie,{[0,1] :foo [1,1] :bar}
21:40clojurebot{[0 1] :foo, [1 1] :bar}
21:40jcromartieit seems pretty natural
21:40jcromartieand it's sparse
22:16chouserjcromartie: sure, why not.
22:16chousermaybe a sorted-map, depending on how you intend to use it
23:23mquanderi'd like to have a function that either takes a number n, a number n and a list of strings xs, and if i pass it a number n and a single string x, i'd like to treat that string as a list of one string
23:23mquanderis there a nice way to do this?
23:24mquanderoh nevermind
23:24mquanderi figured out how to do it using apply
23:34technomancygiven a var that's bound to a function and a list of arguments to apply, is there anyway to tell if the arity is correct by looking at the :arglists metadata?
23:34technomancyI mean a built-in function?
23:35hiredman,(:arglists (meta #'+))
23:35clojurebot([] [x] [x y] [x y & more])
23:35technomancyI guess it wouldn't be terribly hard to just figure it out with reduce
23:35hiredman,(map count (:arglists (meta #'+)))
23:35clojurebot(0 1 2 4)
23:35hiredmanor something
23:36technomancytrickier to do with varargs though, which is why I'd like something built-in
23:37hiredman,(map #(if (.contains % '&) :vararg (count %)) (:arglists (meta #'+)))
23:37clojurebot(0 1 2 :vararg)
23:52abrooksI'm pretty sure that there's a way to type-hint a defn with its metadata but I'm failing to emit the right words into Google to find it.
23:52abrooksOh, I want to type hint the type on the RETURN Value.
23:54abrooksHm. I should looking core.clj...
23:55abrooksAh... {:tag "[Ljava.lang.Object;"}