#clojure logs

2011-02-02

02:00amalloyieure: i ran into an issue with php-repl when trying to use it for anything complex
02:01amalloyeg, foreach (range(0,10) as $x) {echo $x;}
02:01amalloydoesn't work because you're doing eval('return foreach (...) {...};')
02:02amalloyi can fix this by writing function f() {...} followed by f(), but yuck
02:05chouserthe javascript generated by clojurescript has a somewhat startling number of anonymous inner functions.
02:05chouserand now, to bed.
02:07amalloychouser: startling? i'd expect one for every lexical scope at least
02:08ieureamalloy, I haven’t touched PHP or that code in a couple years. If it’s a big issue for you, I’ll lean into it, though.
02:08amalloyieure: don't bother yourself about it yet. i'll fork it on github and take a look; if it's unexpectedly complicated i'll let you know
02:24fliebelmorning
02:26hoeckmorning
02:31amalloymorning fliebel
02:33fliebelamalloy: did tonyl finish his code yet?
02:33ieureamalloy, sounds good.
02:33amalloyfliebel: if so he didn't tell me
02:33fliebelokay
02:36fliebeldid you show him the php code?
02:38amalloyfliebel: no, didn't think of it
03:04amalloybut now it's bedtime for me, so you'll have to link him if he shows up, fliebel :P
03:06fliebelamalloy_: good night :)
04:19Licenseraloa
04:39mduerksen,(let [v2scale (fn [s [a b :as v]] (assoc v 0 (* a s) 1 (* b s)))] (time (dotimes [n 1000000] (v2scale 0.2 [2 2]))))
04:39clojurebot"Elapsed time: 1895.93 msecs"
04:40mduerksenthis is the fastest fn i could up with. any suggestions?
04:42mduerksenunchecked-math isn't a great improvement in this case, it's share in the overall execution time is quite small
05:46MrHus, (= 1 -1)
05:46clojurebotfalse
06:58clgvI am curious if anyone tried to build a Clojure DSL for Latex to get rid of some in inadequateness of it...
07:40bartjI have a bunch of extremely ugly code to write
07:41bartjbut, I think Clojure will have an "elegant" way of writing it
07:41bartjhere is the task:
07:41bartjvalues = v1, v2, v3 and there are fields f1, f2, f3
07:42bartjI need to concatenate the fields f1-v1, f1-v2, f1-v3 if f1 exists
07:42bartjditto with f2, f3
07:42bartjmy normal way of doing it is:
07:42bartj(for [v values] (if f1 (str f1 "-" v)) (if f2 (str f2 "-" v)) ....
07:43bartjI was wondering if there is a better way ?
07:46clgv(map #(when %1 (str %1 "-" %2)) fields values)
07:46clgvdoes that work for you?
07:48clgv&(map #(when %1 (str %1 "-" %2)) ["f1" "f2" "f3"] [1.0 2.0 3.0])
07:48sexpbot⟹ ("f1-1.0" "f2-2.0" "f3-3.0")
07:48clgvas test
07:49ogonzalezbartj, using for: (for [f f-values v values :when f] (str f "-" v))
07:49ogonzalezI think it's right
07:51ogonzalez&(for [f ["f1" nil "f2"] v ["v1" "v2"] :when f] (str f "-" v))
07:51sexpbot⟹ ("f1-v1" "f1-v2" "f2-v1" "f2-v2")
08:39bartjogonzalez, yep, will try that
08:39bartjogonzalez, thanks!
09:28pppaulhow do i add a classpath to clojure while it's running?
09:28dnolenpppaul: no reliable way to do that.
09:29pppauloh
09:29pdkhttp://stackoverflow.com/questions/402330/is-it-possible-to-add-to-classpath-dynamically-in-java
09:29pdkjava isn't really built for this but look into URLClassLoader it seems
09:30pdkremember java comes from the mindset of the old c style write compile run debug loop
09:30pppaulhmmm
09:30AWizzArdInstead of directly the URLClassLoader one could also have a look at the DynamicClassLoader that ships with Clojure.
09:31AWizzArdThis IS an URLClassLoader too.
09:31AWizzArdhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/DynamicClassLoader.java
09:41edwAny cake users here?
09:42edwI'm trying to add /usr/local/share/java to my java.library path and am putitng an entry into $PROJECT/.cake/config with no success.
09:44dnolenedw: what does you entry look like?
09:45edwLine 1: "project.library.path = /usr/local/share/java"
09:45edwLine 2 is the same, but cake.library.path.
09:45edwDo I also need to add a "native-path" entry to my project.clj?
09:46dnolenedw: if you're on 0.6 I think the syntax changed, jvm.opts = -Xms1024M -Xmx2048M -Dfoo=bar
09:47nurv101Question here: is it possible to create a lisp closure in clojure?
09:47edwAh. I'll check that out. Are they additive i.e. can I put that in $HOME/.cake/config and it'll be concatenated with the projects .cake/config file?
09:48dnolennurv101: yes
09:48raeknurv101: what exactly do you mean by "lisp closure"?
09:48nurv101dnolen: how?
09:48nurv101raek: (let ((x 0)) (defun foo() (incf x)))
09:48dnolenedw: no they are separate.
09:49edw(let [x 12] (fn [] x))
09:49raek(defn create-counter [a (atom 0)] (fn [] (swap! a inc)))
09:49edwAhh. Okay.
09:49raeknurv101: ^
09:49nurv101raek: that is not a clojure
09:50raekclojure won't allow you to change the local introduced by let
09:50nurv101raek: closure i mean
09:50raekif that was your question
09:50nurv101raek: i know
09:50raekevery time you call create-counter, you will get a function with its own atom
09:50nurv101the problem is that even local-vars can't be change
09:51nurv101that way
09:51raekin clojure, you have to have some form of mutable cell that does the change part
09:51raeki.e. an atom, agent, ref, or var
09:52raekall these have their own approach to what mutation means in a concurrent context
09:53edwBut the answer to your question is that yes, clojure has lexical scoping aka closures.
09:54raekyes. functions close over their free variables.
09:54edwYes.
09:55nurv101lexical scope isn't a clojure
09:55nurv101closure
09:57mefestoGood morning everyone.
09:58mefestoIf i wanted to send some clojure data over the network using pr and read -- is there a preferred content-type for this?
09:58mefestoapplication/clojure-source or something?
09:59edwnurv101: A closure is an artifact of lexical scoping combined with the ability to declare a procedure in the scope of another.
10:00raeknot that I'm aware of. I used "text/x-clojure-source" to mimic "text/x-java-source"
10:01mefestoraek: works for me, thanks :)
10:01raekthe "x-" means that it hasn't been registered
10:12akopaA bit rough, but here's an clr interop example adapted from RDNZL for Common Lisp: https://gist.github.com/807795
10:23edwHas anyone used zmq and cake on osx? My forehead is bloody from beating it against my monitor.
10:29__name__hi
10:31raekif __name__ == "__main__": print "__name__: hi"
10:32__name__Could any of you be ask kind as to express criticism about https://gist.github.com/806541, I'd like to know where I can improve.
10:53semperosI call a function A which returns a vector; I need to call a function B which takes the _contents_ of the vector, like splicing; what's the proper way to handle this?
10:54mefestosemperos: (apply B [1 2 3])
10:54__name__semperos: do you mean (apply + [1 2 3])
10:54mefestosemperos: is the same as calling: (B 1 2 3)
10:55semperosmakes sense
10:55semperosthanks, simplest things escape me sometimes...
10:56pdkyou can also put extra args in front of the vector
10:56pdkso (apply + 1 2 3 [4 5 6]) is the same as (+ 1 2 3 4 5 6)
10:57__name__i wish apply and partial had shorter names
11:11edwIn cake, "ext-dependencies", what are these things? I'm currently going through the source code, but if cake's project file format is documented anywhere, that would be great.
12:06edwIs there a safe way to eval strings? Basically a JSON-y reader procedure?
12:50phenom_im having a bit of trouble with cake ... I created a project.clj file correctly and added a single file in the test folder (chapter08/date-operations-spec.clj) but when I run "cake test" it complains (hapter08/date_operations_spec.clj on classpath, note the underscore's)
13:30Scriptorhey everyone, I have a question about the sequence implementation as described in http://blog.higher-order.net/2009/02/01/understanding-clojures-persistentvector-implementation/
13:32Scriptorsay you have <32 elements, and you cons a new element on the vector
13:33Scriptorfollowing that code, it seems like it finds the right and bottom-most array, and copies it
13:34Scriptorwhat exactly is the new root being created with such a cons?
13:46amalloyScriptor: as i understand it, if you have fewer than 32 elements and cons another, it copies the whole thing
13:46amalloywell. conj, not cons
13:47Scriptoramalloy: by the whole thing, you mean just that set of <32 elements, right?
13:47amalloyScriptor: yes, since that is the whole thing
13:47Scriptorisn't that still a little inefficient?
13:48amalloyedw: maybe check out clojail
13:48Scriptorok, the whole thing could be the whole tree too, right? :)
13:48amalloyScriptor: i don't understand. if you have less than 32 elements, the tree is a single node
13:49Scriptoramalloy: oh, I meant 32 elements in the rightmost and bottom-most set of elements
13:49amalloyedw: it's the safe-evaluation library Raynes and i have put together, and it's what sexpbot uses. see, for example, ##(inc (eval (read-string "2")))
13:49sexpbotjava.lang.SecurityException: You tripped the alarm! eval is bad!
13:50Scriptorfor example, looking at the diagram, if we imagined that red series of 1..32 was instead something like 1..14
13:50Scriptorer, 0..14
13:50Scriptorand we added another element to it
13:50amalloythen yes, those 32 elements are copied
13:51amalloyand that's inefficient but unavoidable, and not terribly inefficient
13:51Scriptorah, I understand now, thanks!
13:51amalloyone malloc and 32 pointer copies?
13:52Scriptorright, it uses System.arraycopy
13:52Scriptorwhich I guess would be pretty efficient
13:52amalloyprobably
13:52amalloyand iirc it has to make a copy of every node heading up to the root, but that will be a pretty small number
13:59pdkokasaki's book is a good primer on functional data structures scriptor
14:01Scriptorpdk: is his thesis paper a good substitute
14:01Scriptor?
14:01ScriptorThat's what I've been trying to use
14:01pdkthe book expands it some and adds haskell translations of the ML code samples
14:02Scriptorooh, haskell translation would be nice
14:02Scriptorargh, still pricey though :/
14:03ossarehmorning all
14:03Scriptormorning ossareh
14:04pdkoh wow it's on kindle now
14:04Scriptoryep, I have one too
14:05ScriptorI just wish I knew for certain I'd read it
14:05Scriptorwould you say the book is more beginner-friendly?
14:05ossarehwhich book?
14:05pdki haven't completed it but i doubt it'll be much less dense
14:05pdkaside from adding introductory bits
14:05pdkwith stuff like the tree copying example
14:06Scriptorossareh: purely functional data structures
14:07ossarehScriptor: ah - nice - man that was a hard read
14:13Scriptorossareh: I know! I'm honestly still trying to find a detailed enough explanation of amortization
14:13__name__I know I already posted it, but I think the message was not noticed (and I updated the code): Please tell me if you can see anything unidiomatic in https://gist.github.com/806541.
14:15opqdonutlooks ok
14:22shortlordHow can I import a simple .java file that is placed in the same directory as the clojure files?
14:23shortlordI have written a file called Foobar.java
14:23shortlordand used :import [Foobar]
14:23__name__opqdonut: Thanks
14:23shortlordbut (Foobar/foo "test") still doesn't work
14:23mefestoshortlord: did you compile it and it's class is on the classpath?
14:25shortlordmefesto: I have compiled it using javac
14:25mefestoshortlord: are you using leiningen or cake for building this project?
14:25shortlordI am using cake
14:26amalloy__name__: i don't think we use lazy-cat anymore
14:26__name__amalloy: what else?
14:27mefestoshortlord: i haven't tried a mixed java + clojure source project using leiningen (or cake) so I'm not sure if this is necessary but did you specify a :java-source-path in your project.clj?
14:27shortlordmefesto: no, I didn't. Do you have any link about the :java syntax?
14:27amalloyi'm still working through what you're actually *doing*, but it seems like you're using ::p as a sentinel "non-data" value. i usually use (complement #{::p}) rather than #(not= ::p %) for that, but it's not 100% clear it's applicable to your case
14:28amalloyoh, you mean what instead of lazy-cat?
14:28mefestoshortlord: im going by this leiningen example: https://github.com/technomancy/leiningen/blob/stable/sample.project.clj
14:30shortlordmefesto: thx, I will look at that
14:30__name__amalloy: yes
14:30amalloyconcat should be lazy enough for your purposes
14:30__name__so concat is lazy by default?
14:31amalloy$source concat
14:31sexpbotconcat is http://is.gd/e8fROL
14:31amalloythe source is messy because of optimizations, but you can see it's wrapped with lazy-seq
14:32__name__where's the difference to lazy-cat then?
14:32amalloylazy-cat is a relic of 1.1, i think
14:32amalloyie, there's no reason to use it
14:32__name__amalloy: fair enough, thank you
14:33brehautmorning
14:33__name__good morning, brehaut
14:33amalloyhola brehaut
14:34__name__amalloy: the source to concat confuses me :)
14:34brehaut$source concat
14:34sexpbotconcat is http://is.gd/e8fROL
14:36brehaut__name__: are you focusing just on the arity-2 version?
14:37__name__yes
14:38amalloy__name__: ignore the chunked half, too
14:38brehautthe guts of the algorithm is the else part of the inner most if; everything else can be handwaved as 'implementation details'
14:38__name__(cons (first s) (concat (rest s) y))
14:38__name__that?
14:38brehautyup
14:39__name__$source cons
14:39sexpbotcons is http://is.gd/5brDTa
14:39brehautie a recursive call. it doesnt blow stack because concat is wrapped in a lazy-seq
14:39brehautcons is the singlely linked list / seq equivalent of conj
14:40__name__fair enough, fp still sort of confuses me by times
14:40amalloy(defn my-cat [x y] (lazy-seq (let [s (seq x)] (if-not s y (cons (first s) (concat (rest s) y)))))) would be a simple version, and i think correct
14:41amalloybrehaut: did you do something weird when talking about wrapping? i see a \u0008 character right before "wrapped"
14:42brehauti dont ithnk i did?
14:43brehautamalloy: i thik your version is correct yes
14:43__name__amalloy: that makes sense
14:43amalloy__name__: oh good
14:43__name__thank you very much, amalloy
15:00opqdonutthis is weird
15:00opqdonut(first (map prn [1 2 3])) prints all of the numbers
15:01opqdonuteven though (map prn [1 2 3]) has class clojure.lang.LazySeq and chunked-seq? returns false for it
15:01opqdonutis there something I'm missing?
15:01amalloyopqdonut: chunked-seq? isn't very reliable in my experience
15:02opqdonutis there some way I can force a seq to be one-by-one
15:02amalloyit's definitely a chunking issue
15:02opqdonutyes, I figured as much
15:02opqdonut(this is 1.2.0)
15:02amalloyummmmm, i'm gonna make chouser answer that question. he put some kind of unchunker in JoC
15:02tomoj&(class (next (map prn [1 2 3])))
15:02sexpbot⟹ 1 2 3 clojure.lang.ChunkedCons
15:03amalloy&(class (seq (map prn [1 2 3])))
15:03sexpbot⟹ 1 2 3 clojure.lang.ChunkedCons
15:03opqdonutindeed
15:03amalloybefore the seq call, it can't know that the underlying lazy seq will be chunked
15:04tomojis it the side-effects you're worried about?
15:04opqdonutI'm worried about consistency
15:04opqdonutI'm teaching a course on clojure...
15:04tomojI recommend teaching them not to pass side-effecting functions to map :)
15:05opqdonutthat I am doing, I'd just like to demonstrate laziness
15:06amalloy&(first (iterate #(do (prn %) (inc %)) 0))
15:06sexpbot⟹ 0
15:06amalloy&(second (iterate #(do (prn %) (inc %)) 0))
15:06sexpbot⟹ 0 1
15:07opqdonut&(first (map prn (range)))
15:07sexpbot⟹ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 nil
15:07opqdonut&(first (map prn (repeat 50 "!")))
15:07sexpbot⟹ "!" nil
15:08tomojcould be dangerous
15:10tomojimagine defining the ackermann function and using (range), taking a few
15:10shortlorddoes anyone know how to compile .java files using cake?
15:10opqdonuttomoj: indeed
15:12tomojI hardly remember ever having actual problems from it
15:26LauJensenshortlord: AFAIK the cake javac plugin is loaded by default, so it should just pick up the java files and compile them, try asking in #cake.clj if you have any problems
15:26amalloyfwiw opqdonut i've never been impacted by chunking
15:26opqdonutwell me neither
15:26amalloyit's something that sounds appalling but winds up not really mattering
15:26opqdonutthat's why I was kinda surprised
15:28opqdonutfor educational reasons I'd like a dechunkifier
15:28opqdonut(defn my-seq [s] (map first (iterate next s))) seems to work at least
15:29amalloyopqdonut: really? i don't think you can unchunk a seq that's already chunked; you have to prevent it happening in the first place
15:30opqdonutthat's what I meant, of course
15:30shortlordLauJensen: thx for the suggestion, javac does not seem to be loaded with cake by default, but I managed to get it working with lein javac
15:30opqdonutso (first (map prn (my-seq [1 2 3]))) prints only 1
15:31shortlordis there something like :reload-all for imports?
15:32amalloyshortlord: i don't think so. java doesn't like classes to change at runtime
15:33shortlordamalloy: I'd like to reimport them in clojure without restarting the REPL though
15:35shortlordamalloy: is there really no way of doing it? it should not be too different from how clojure does it itself, right?
15:35shortlordit works as soons as I restart them REPL and then import the file again, but always closing and restarting the REPL kills the dynamic workflow
15:36brehautshortlord: but for a dynamic workflow you infrequently need to reload more than one ns
15:36opqdonutyou can google "java class reloading" and read all the problems :)
15:37amalloyi don't know. clojure does it, i think, by re-reading the .clj files and generating new classes with different (?) names
15:40ossarehhm, if that were the case permgen would run out - and i've not seen that to be the case in any of my super long running repl sessions (often weeks at a time between restarts)
15:41raekhrm. when was support for docstrings in 'def' added?
15:42opqdonut&(doc def)
15:42sexpbotjava.lang.SecurityException: You tripped the alarm! def is bad!
15:42opqdonut:D
15:42opqdonutokay then
15:43arohnerossareh: permgen is GC'd when the classloader that created the class is GC'd
15:43raekhttp://clojure.org/special_forms says (def symbol doc-string? init?)
15:43arohnerossareh: err. classes *can* be GC'd *after* their classloader is GC'd
15:44opqdonutin practice getting classes to GC can be bothersome
15:44arohnerclojure gets around the permgen issue by creating a new classloader each time it creates classes
15:44brehautraek: presumably thats in 1.3 cause 1.2 erros if i actually try it
15:44ossareharohner: ah, I didn't know that - cool. Cheers.
15:44opqdonutwhen I last meddled in classloaders I think I ended up creating one per loaded class
15:45opqdonut(the program was generating a ton of one-off classes)
15:45ossarehopqdonut: right - I had a similar issue with a simple web app hosted in jboss, a few deploys and I guess something was keeping class headers around.
15:58raekwhat is the preferred way of testing private variables with clojure.test? @#'foo? something else?
16:05pjstadigamalloy: the compiler generates new class names using a global serial number in clojure.lang.RT
16:07pjstadigraek: fogus wrote a macro http://blog.fogus.me/2010/09/03/monkeying-with-clojures-deftest/
16:07pjstadigor you could just @#'foo
16:10sritchiehey all -- I have two clojure functions that are very similar, and wanted to ask advice on how to abstract out the common pattern. here are the functions -- https://gist.github.com/3148f33f2702b029fe78
16:10sritchieI could have all-files call files-with-names and simply not return the ?filename, but the function is exactly the same length
16:11brehautwhere is <- defined?
16:11edwIt's cascalog.
16:11brehautoh, cascalog?
16:11sritchiebrehaut: it's a cascalog macro
16:11sritchiebrehaut: uip
16:11sritchieyup
16:12sritchieI suppose I could just give two vectors, input args and output args,to a function
16:12sritchieand have it return the common function
16:13kumarshantanuhi, can anybody let me know how can i easily extend IFn of invoke (arity 2) to a type?
16:14kumarshantanuthere are like 21 arity signatures for invoke in IFn, and i don't need all of them
16:22tomojdo you own the type?
16:22tomojdeftype/defrecord? or what?
16:23raekkumarshantanu: from java or using proxy: extend AFn instead of implementing IFn
16:24sritchiebrehaut: they're similar, but I'm not sure what the pattern is --
16:24sritchiein one case, I'm dropping one of the fields
16:25brehautim not sure im much help, i dont know cascalog at all
16:25brehautdo you only have the two functions?
16:26amalloysritchie: i suspect that <- is a macro in cascalog, so you can't generalize it without adding a macro of your own - a function can't usefully call it since the options will need to be available at compile time
16:27sritchieamalloy: in this case, is it worth it to keep the duplication?
16:27sritchieamalloy: the other option is to have the tap return filename for everything, and just ignore it further down the road
16:27sritchieamalloy: as that's essentially what "all-files" does anyway
16:28amalloyeg (defmacro casca-fn [name doc v1 v2] `(defn ~name ~doc [arg#] (let [source# (hfs-whole-file arg#)] (<- ~(vec v1) (source# ~@v2)))))
16:29amalloyi don't know anything about cascalog, but that's a macro you should be able to call as (casca-fn all-files "doc" [?file] [?filename ?file]) to reproduce your second defn
16:31sritchieamalloy: interesting, let me try that out
16:31sritchieamalloy: this'll be my first macro
16:31amalloysritchie: whew. i just tried it out, and it does
16:31sritchiehaha, someday I'll be able to churn out working macros in IRC
16:35amalloyincidentally, if you wanted to you could eliminate the "source" binding by moving it into the <- in-place
16:42sritchieamalloy_afk: done, and playing with macroexpand
16:43mefesto,(= (into-array Byte/TYPE [1 2 3]) (into-array Byte/TYPE [1 2 3]))
16:43clojurebotjava.lang.IllegalArgumentException: argument type mismatch
16:45mefesto,(java.util.Arrays/equals (into-array Byte/TYPE (map byte [1 2 3])) (into-array Byte/TYPE (map byte [1 2 3])))
16:45clojurebottrue
16:47mefestohmm is there another way to test array equality?
16:47companion_cube,(= [1 2 3] [1 2 3])
16:48clojurebottrue
16:48mefestocompanion_cube: java arrays tho
16:48mefestomore specifically, java byte arrays
16:48companion_cubedon't know
16:50amalloyargument type mismatch? that's a weird exception for that
16:50amalloy&(= (byte-array [1 2 3]) (byte-array [1 2 3]))
16:50sexpbotjava.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Byte
16:50mefestoamalloy: yup, i forgot to (map byte [1 2 3]) it
16:51mefesto&(= (byte-array (map byte [1 2 3])) (byte-array (map byte [1 2 3])))
16:51sexpbot⟹ false
16:51mefestooh well i guess i can live with j.u.Arrays/equals
16:53amalloymefesto: you could seq them
16:53amalloy&(apply = (map seq (repeatedly 2 #(byte-array (map byte [1 2 3])))))
16:53sexpbot⟹ true
16:54mefestoamalloy: sweet, i'll take that over j.u.Arrays. thanks :)
16:54amalloy&(apply = (map identity (repeatedly 2 #(byte-array (map byte [1 2 3])))))
16:54sexpbot⟹ false
16:54amalloyyeah, just checking. seq is the magic
16:55opqdonutgah, lein fails
16:55opqdonutcan't find org.clojure:clojure:jar:1.2.0
16:55raekopqdonut: newest version?
16:55raekdone lein self-install?
16:56opqdonuti downloaded the script and said "lein"
16:56opqdonutlet's try self-install
16:56opqdonutok, that seemed to do something
16:58raekopqdonut: it seems that in the latest versions, self-install should be automatic when you use lein the first time
16:58opqdonutok
16:58raekyou used the stable version, rigth? https://github.com/technomancy/leiningen/raw/stable/bin/lein
16:58opqdonutyeah
17:00opqdonuthmm, "lein repl" still complains about org.clojure:clojure:jar:1.2.0 and org.apache.maven:super-pom:jar:2.0 missing
17:00opqdonutI kinda hate all these language-specific frameworks, I'm fighting with leiningen *and* cabal at the moment...
17:02amalloyopqdonut: lein repl wants you to be in a project
17:03amalloycake repl will implicitly use the global project
17:03technomancyactually lein repl will run in leiningen's classloader if you're outside a project.
17:04amalloytechnomancy: sorry, i try to avoid singing only-cake's praises, but i forgot this time :)
17:04technomancymissing clojure.jar sounds like a firewall issue
17:04opqdonutI'm in a project as far as I know
17:05opqdonuttechnomancy: nah
17:05opqdonutoh, that's funny
17:05opqdonutException in thread "main" java.net.SocketException: Network is unreachable (NO_SOURCE_FILE:0)
17:06opqdonutI can ping repo1.maven.org and clojars.org just fine
17:06opqdonutand browse them too
17:06opqdonutand I'm on a basic adsl line
17:09technomancynet neutrality?
17:09technomancyfor Leiningen access you need the Premium Developer Plus DSL bundle.
17:09opqdonuthar har
17:10opqdonutlet's try straceing the call
17:10opqdonut32316 --- SIGSEGV (Segmentation fault) @ 0 (0) ---
17:11opqdonut32316 getsockname(0, 0x7f7c84a8df90, [28]) = -1 ENOTSOCK (Socket operation on non-socket)
17:11opqdonutthis sounds bad
17:11kryfttechnomancy: Is this something like expensive speaker cables?
17:11technomancyright
17:11sritchiecan anyone recommend a good tool for counting lines of code in a leiningen project?
17:11opqdonuthmm, okay, for some reason it's trying ipv6 addresses
17:12kryftsritchie: Are you charging per line?
17:12sritchiehaha, no, they'd soon realize that clojure could all be one line, technically
17:12sritchieI'm revamping a rather large python project using clojure, and want to make a point to the team
17:12amalloysritchie: as could anything but python :P
17:13sritchieamalloy: true, as I'm comparing to python, maybe my comparison should be: here's our former huge application, in one line.
17:14raekopqdonut: could you try renaming your .m2 folder to something else and try again?
17:15amalloysritchie: $ find -name '*.clj' | xargs perl -n -e 'print unless (/^\s*(;.*)?$/);' | wc
17:15amalloyis what i use
17:15opqdonutraek: same problem
17:15opqdonutI even removed all ipv6 addresses from my interfaces
17:19opqdonutah found the debian bug report for this
17:25amalloyi see my suggestion was so awesome it broke sritchie's net connection
17:26opqdonutyay, workaround
17:59scottjAre there any tricks for making lein behave better when there's no internet connection available? does only lein deps cause it to check for updates to dependencies that are SNAPSHOT?
18:01arohnerscottj: lein uses maven under the hood. Have you looked at the offline settings in http://maven.apache.org/settings.html?
18:01technomancyscottj: the Maven API exposes a "don't check for snapshots" setting, but it seems to have no effect in my brief experience with it.
18:02technomancyscottj: but if there are no SNAPSHOT deps and dependencies are in ~/.m2, then an Internet connection isn't needed
18:02technomancysee also :checksum-deps in lein 1.5
18:25sritchiehey all -- when defining a multimethod, what's a clean way to direct, say, both byte-arrays and files to the same method?
18:29wolverianis there a nicer way than (every? identity coll)? (apply and coll) doesn't work, of course.
18:30technomancywolverian: there's an open ticket for that
18:30technomancyhttp://dev.clojure.org/jira/browse/CLJ-450
18:35wolverianthat'd be nice.
18:36technomancyI concur.
18:36amalloysritchie: ##(doc derive)
18:36sexpbot⟹ "([tag parent] [h tag parent]); Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualified symbol or keyword and child can be either a namespace-qualified symbol or keyword or a class. h must be a hierarchy obtained from make... http://gist.github.com/808684
18:37sritchieamalloy: great, just ended up deriving both from ::fileable
18:37sritchiethanks
18:37amalloyyeah, that's what i was going to suggest
18:38sritchieamalloy: all of this syntax ends up being so clean! I'm feeling much clojure love
18:39amalloyheh. and now you can count lines, too, right?
18:55pppaulanyone know how to use fixtures?
18:55mefestopppaul: clojure.test fixtures?
18:55pppaulyup
18:56pppaulwhen i read about them it tells me to add them to the namespace
18:56pppauli tried in the (ns ) macro, but that gave me errors
18:56mefestopppaul: yeah there is a function called clojure.test/use-fixtures i think
18:57pppaulso, i just put that in my file and that's it? (that's what have now... haven't been able to run my tests cus i'm fighting with classpaths again)
18:58mefestopppaul: http://clojure.github.com/clojure/clojure.test-api.html
18:58pppauli've read that
18:58pppaula few times
18:59mefestopppaul: in your test ns you define your fixture functions (ex. my-fixture) then call (use-fixtures :each my-fixture)
18:59pppaulok, maybe i'm doing it right
18:59pppaulug, just crashed lein because my classpath for testing was wrong :(
19:01mefestohttps://gist.github.com/808773
19:54sritchiehey all -- I'm looking for an idiomatic way to take every odd element in a collection
19:55technomancy,(doc keep-indexed)
19:55clojurebot"([f coll]); Returns a lazy sequence of the non-nil results of (f index item). Note, this means false return values will be included. f must be free of side-effects."
19:55amalloysritchie: take-nth
19:56amalloyor wait, do you mean every second element, or every element whose value is odd?
19:56sritchieevery second element
19:56amalloy&(take-nth 2 (range 20))
19:56sexpbot⟹ (0 2 4 6 8 10 12 14 16 18)
19:56sritchie,(take-nth 2 (range 24))
19:56clojurebot(0 2 4 6 8 10 12 14 16 18 ...)
19:56sritchiecool, that's great
19:57sritchiethanks a lot
19:57sritchieI'm slowly absorbing the sequence API
19:57brehaut,(take-nth 2 (rest (range 24))
19:57clojurebotEOF while reading
19:57amalloysritchie: nobody can absorb it all, except chouser
19:57brehaut,(take-nth 2 (rest (range 24)))
19:57clojurebot(1 3 5 7 9 11 13 15 17 19 ...)
19:58sritchiedoc in the repl is extraordinarily helpful
19:58brehauthah
19:58brehaut&(doc apropos)
19:58sexpbotjava.lang.Exception: Unable to resolve var: apropos in this context
19:59amalloy$findfn 2 (range 10) [0 2 4 6 8]
19:59sexpbot[clojure.core/take-nth]
19:59amalloysritchie: sexpbot also has a handy little thing for you
19:59brehautamalloy: what are the limits on the syntax for $findfn ?
19:59amalloyit's not very flexible, but it can help if you know what you're looking for but not what to call it
19:59sritchieamalloy: wow, that's really handy
19:59brehautsritchie: also look at at clojure.repl/apropos
20:00amalloybrehaut: no particular limits. it takes N forms, interprets the last as a return value and the rest as args
20:00brehautit lets you search all the currently loaded ns's for a regexp or string
20:00amalloyit evals each form in the same sandbox it uses for ##(count "other stuff")
20:00sexpbot⟹ 11
20:01amalloyi suppose i could try permuting the arguments so that $findfn (range 10) 2 [0 2 4 6 8] also worked
20:01technomancy$find-fn false (loop [] (recur))
20:01technomancyooops; missing a # there
20:01brehaut$findfn (fn [a b] (cons b a)) [] [1 2 3] (3 2 1)
20:01sexpbotjava.security.PrivilegedActionException: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0)
20:02technomancywas hoping to have it solve the halting problem
20:02sritchiehaha
20:02sritchieand then the forum would implode
20:02brehaut$findfn (fn [a b] (cons b a)) [] [1 2 3] (list 3 2 1)
20:02sexpbotjava.lang.Exception: Unreadable form
20:03brehautwhats unreadable about that?
20:03amalloybrehaut: dunno
20:03amalloytechnomancy: it should be eval'ing this in a timeout context. i don't quite see why you never got an exception
20:04technomancyruh roh
20:04brehautsomewhere a core is getting hot
20:07amalloylol, no, it probably just doesn't send a message in certain error cases. tbh it's been a while since i wrote this
20:07amalloyalso sritchie, you can /msg sexpbot if you want to try things like findfn without cluttering #clojure
20:07brehautwhile that is clearly better, its a ilittle disappointing :P
20:07amalloyyeah
20:08sritchieamalloy: good advice
20:08sritchieamalloy: is there anything like sexpbot out there?
20:09sritchieamalloy: what's the competition look like?
20:09amalloysritchie: clojurebot
20:09amalloy,'meeeeee
20:09clojurebotmeeeeee
20:09amalloyand there are loads of irc bots for various languages
20:10brehauthash haskell has a pretty cool one
20:10amalloy$help heval
20:10sexpbotamalloy: Evaluates Haskell code with mueval.
20:10bhenry1the sexpbot irc room needs a name change to avoid the occasional creeper in there.
20:10amalloybhenry1: yeah, that's funny stuff
20:12brehautheval take 10 $ let fib = 1 : 1 : zipWith (+) fib (tail fib) in fib
20:13brehautuh oh
20:13brehautdo i need to message it directly to sexpbot?
20:16amalloybrehaut: $heval
20:16brehaut$heval take 10 $ let fib = 1 : 1 : zipWith (+) fib (tail fib) in fib
20:16sexpbot⟹ [1,1,2,3,5,8,13,21,34,55]
20:16brehautaha
20:17amalloysexpbot's commands need to be prefixed with $, or anything /msged will be tried as a command
20:17brehautah right of course
20:37defnanyone have the "State of the Art" setup for vim and clojure? Don't worry guys, it's for a friend... :D
20:37brehauta friend eh :P
20:39defnbrehaut: i have my hand over my heart as we speak
21:37bartjis it possible to partition a sequence using a regex ?
21:37bartjgrr, re-seq
21:38brehautbartj: can you rephrase the question? its a bit ambigious
21:39brehautperhaps and example of your hypothetical inputs and outputs?
21:40bartjbrehaut, basically a re-split which works on sequences ?
21:41bartjeg: (func #"^$" ["a" "b" "" "c" "d"])
21:41bartjwould give (("a" "b") ("c" "d"))
21:45brehautbartj: hmm. partition-by will get you half way there
21:46brehaut,(partition-by empty? ["a" "b" "" "c" "d"])
21:46clojurebot(("a" "b") ("") ("c" "d"))
21:47bartjbrehaut, that's exactly what I need, thanks!
21:48brehautbartj: its not _exactly_ it
21:48brehauta: the pivot is still present
21:48brehautb: it'll pivot again if another empty string is found
21:49brehaut,(partition-by empty? ["a" "" "b" [] "c"])
21:49clojurebot(("a") ("") ("b") ([]) ("c"))
21:49bartjthough, I am stumped by:
21:49bartj,(empty? '())
21:49clojurebottrue
21:49brehautthe empty list is empty?
21:50brehautpartition-by partitions the seq whenever the result of the fun its provided changes
22:01brehautbartj: heres an exceedingly scruffy pivot-on fun that does what you wanted https://gist.github.com/808961
22:02brehautand by exceedingly, it looks like a cat wandered into a text editor and vomited up square brackets
22:03brehautthe clearly ignores the obvious optimisation of just using the remainder as 'r' as soon as the pivot predicate is matched
22:08pdk`could always be fancy and write (vec this that...) everywhere
22:08pdk`if those []s bug ya
22:09pdk`i assume this is for a functional version of quicksort or something?
22:09brehautpdk oh man i hope not :P
22:10bartjbrehaut, thanks, I think I'll stumble through
22:10bartjI've used:
22:10brehautbartj: i have a loop recur version that is cleaner :P
22:11bartjbrehaut, thank you, I am done with what I want :)
22:11brehauthaha
22:11brehautno problem
22:12brehauti just couldnt leave the scruffy version as the only version :P
22:14gfrlog(doc vec)
22:15gfrlog,(doc vec)
22:15clojurebot"([coll]); Creates a new vector containing the contents of coll."
22:15clojurebotExecution Timed Out
22:15gfrlogI knew (vec this that) didn't make sense
22:16brehautgfrlog: it'll fit right in with my terrible function implemention :P
22:20pdk`well
22:20pdk`vector :p
22:20bhenry,(vector :this :that)
22:20clojurebot[:this :that]
22:20pdk`hmm
22:21pdk`(fn [[[l r] pivoted] v]
22:21pdk`what exactly is going on with the destructuring for the fn args there
22:21brehautyikes man, no need to go spread that mess about :P
22:21pdk`it's a learning exercise :p
22:21brehautok
22:22brehaut(pivot-on empty ["a" "b" "" "c" "d"]) ;=> [["a" "b"] ["c" "d"]]
22:22brehautin the reduce, im using a vector as a pair for my accumulator
22:23brehautthe pair consists of the final result (another pair of vectors) and a flag to tell the reducer if it has pivoted
22:25brehautpdk`: does that make it clearer?
22:26bartj,(doc pivot-on)
22:26clojurebotExcuse me?
22:26bartjhuh?
22:27zippy314Hi. How do I determine if a cloujure object is callable as a function?
22:27brehautbartj: its in that gist i made
22:27bartjoh
22:27zippy314i.e. would return true for a keyword but false for an integer
22:27bartjzippy314, ASFAIK most clojure objects *are* functions
22:27bartjeg:
22:27brehaut,(fn? inc)
22:27clojurebottrue
22:27brehaut,(fn? {})
22:27clojurebotfalse
22:28brehaut(ifn? {})
22:28bartj,(doc keyword?)
22:28brehaut,(ifn? {})
22:28clojurebot"([x]); Return true if x is a Keyword"
22:28clojurebottrue
22:28bartjzippy314, here is my version:
22:28bartj(if (keyword? obj) true false)
22:29brehautzippy314: ifn? for anything callable, fn? for actually a function
22:29zippy314thats it!
22:29zippy314,(doc ifn?)
22:29clojurebot"([x]); Returns true if x implements IFn. Note that many data structures (e.g. sets and maps) implement IFn"
22:29brehautbartj: that can be reduced to (keyword? obj)
22:29phenom_out of curiosity, what is the plan for binding in clojure 1.3?
22:31dnolenphenom_: plan ?
22:32phenom_dnolen: rebinding a function in a binding clause no longer works in 1.3, but does for 1.2
22:33brehautphenom_: by default. if you add the :dynamic meta to the var it does
22:34phenom_hmmm, correct me if im wrong (and i mean in that in the newbie sense not in the pretentious sense) but does that mean I need to know ahead of time which functions will potentiall be rebound and add the :dynamic meta info ?
22:34brehautyes
22:34pdk`i was asking more about the args list for the fn in the line i posted bartj
22:35RazwellesHow do you load a .net dll and use its classes in clojureclr?
22:35pdk`how you got 2 levels of nesting going on in the args list so i was wondering how the destructuring there was playing out
22:35brehautphenom_: its good practise to *ear-muff* your rebindable vars anyway
22:36phenom_brehaut: how would stubbing or mocking work for testing ?
22:36brehautphenom_: pass?
22:37phenom_brehaut: :S im not familiar with that
22:37brehautphenom_: i mean i dont know sorry
22:38phenom_brehaut: kk, thnx
22:41dnolenphenom_: known issue, http://clojure-log.n01se.net/date/2010-10-29.html
22:42dnolenphenom_: not sure if it's been addressed yet.
22:43dnolenphenom_: it can be done by changing the var root binding, but I think it's a bit tedious, thus the discussion about a convenience macro for mocking/stubbing.
22:47phenom_dnolen: good catch, thnx :)
22:50pppaulanyone here work with lein?
22:50bhenrypppaul: what;s up?
22:50pppauli'm trying to do testing in it, but i'm not sure how to set up my namespace
22:50bhenryyou mean like lein test?
22:52pppaul(ns test.solve360.name-fixer is my namespace, but when i run lein test it breaks. my folder structre is /test/solve360/name_fixer.clj
22:53pppaultest/ is in my classpath too
22:54pppaulalso, when lein test is run, lein totally breaks... i need to restart it
22:55bhenrytry ns solve360.name-fixer
22:55bhenryhttps://github.com/technomancy/leiningen/blob/master/test/test_compile.clj
22:55bhenryexample
22:55bhenry^^^ pppaul
22:57pppaulthanks
22:58pppaulhow would that namespace work? because i have that namespace already taken in my src dir
22:58bhenryi think that's why all the leiningen tests have test in the name.
22:59bhenryjust change the name of your test file to test-name-fixer
22:59pppaulseems a bit redundant
22:59pppaulthanks, though
23:00bhenrypppaul: i agree.
23:00pppauloh, i think i did it wrong... should be solve360.test.name-fixer
23:00pppauli hope
23:01pppaulyup, works
23:02bhenrycool.
23:02bhenryi haven't done too much with testing. should probably get in the habit of that.
23:06pppauli really need to test, i can't trust my code
23:31brehauttechnomancy: does lein backup the 'lein' script when you do upgrade ?