#clojure logs

2012-01-01

05:02lypanovhey, is there a way to set a variable like this "(def *vm-session-type* "headless") from another file?
05:03lypanovi imagine its basic clojure knowledge. but i don't have time to finish my joy of clojure and need to get something working today ;)
09:39SomelauwHappy new year
09:40SomelauwI wanted to write a pokerhand recognizer in clojure. This is the code I ended up with for recognizing a full house: http://pastebin.com/q0Z5xBYK. What do you think of it?
10:22wingiehow can i know what a function do in the repl and what args it takes?
10:24gko(doc function)
10:24clojurebotTitim gan éirí ort.
10:24gko,(doc print)
10:24clojurebot"([& more]); Prints the object(s) to the output stream that is the current value of *out*. print and println produce output for human consumption."
10:25wingiegko: thanks
10:25wingie(doc function)
10:25clojurebotExcuse me?
10:25wingie(doc print)
10:25clojurebot"([& more]); Prints the object(s) to the output stream that is the current value of *out*. print and println produce output for human consumption."
10:26wingie(prn 1)
10:26wingie:)
10:31ordnungswidrighi allo.
10:45djh__has anyone ever used clj-http
10:45djh__I'm struggling to get my head around one thing
10:46djh__I'm trying to login to a website
10:46djh__using POST
10:46djh__I can login with my credentials which returns a cookie
10:46djh__but I don't know how to "put" that cookie into subsequent requests
11:05wingiewhy isn't another delimiter used to create a list instead of having it like this: (list 4 3 2 1)
11:06wingie{} and [] are not used using a macro .. so why did they made a decicion that list should also be for execute the first one as function/macro ?
11:07Chousuke(foo bar) already is a list. it just evaluates as a function call.
11:07Chousuke[foo bar] is a vector, aand vectors have different evaluation rules.
11:08Chousukeyou need to either quote the list (to prevent evaluation) or construct the list dynamically via a function call.
11:09wingieChousuke: I see
11:09wingiecould you say that a vector is like an array in other langs?
11:12Chousuke,(let [foo {:bar 'test} bar :bar] ['[foo bar] '(foo bar) [foo bar] (foo bar)]) ; like this
11:12clojurebot[[foo bar] (foo bar) [{:bar test} :bar] test]
11:12xcvwingie: The underlying data structure is quite different, in order to preserve performance guarantees while staying immutable, but apart from the immutable properties, it feels a lot like a python/ruby array
11:13ChousukeI'm in a train and this internet connection is really laggy :P
11:13Chousuketook me a minute to write that example.
11:14Chousukessh is not the most pleasant tool to use with a connection that has 500ms average lag.
11:15wingie:)
11:15wingiexcv: right
11:17Chousukeanyway, the important thing to understand is that (foo bar) is a list, you just can't use them "as is" like vectors because a list is an operator call in clojure.
11:18kzarI want to import [org.apache.commons.lang RandomStringUtils] but I'm not having much luck, do I need to add something to project.clj? (I'm not really clear how you figure that out for Java libraries.)
11:18Chousukein most cases where you'd want a literal list a vector will do just fine anyway
11:19Chousukeit's very rare to see actual calls to list in clojure code (it's more common in other lisps because they don't have vectors with useful evaluation semantics like clojure's)
11:19xcvwingie: As to the question of why lists are evaluated like they are, that comes back to lisp code being represented as lists: the function call reader interpretation for the list (list-as-code) is assumed to be more common than the list-as-data interpretation, so it gets the simpler syntax of the two.
11:21xcvwingie: Lists are basically singly-linked lists, with most of their performance characteristics (linear lookup etc) while arrays behave pretty much like you'd expect arrays to.
11:21Chousukerather, it's impossible to have lists be function call forms while evaluating to themselves at the same time.
11:21xcvhaha! Yep, that would definitely be tricky :P
11:22Chousukeif you have some other syntax for function calls that still somehow used lists, Clojure would lose its homoiconicity.
11:22Chousukeof course, you could have vectors be the function calls but then you'd just have the same problem with vectors instead of lists :P
11:53solussdis using a defn inside of a let good form? I have a bunch of functions that all need to reference the same "global", but I'd rather not put a 'def' at the namespace level
11:53solussde.g. (let [something "some value"] (defn* ….)
11:58SomelauwI wanted to write a pokerhand recognizer in clojure. This is the code I ended up with for recognizing a full house: http://pastebin.com/q0Z5xBYK. The double transformation to a hashmap annoys me a little.
12:00weavejesterThe fullhouse function seems a little heavy for what its doing
12:00SomelauwHeavy?
12:00SomelauwCan it be done simpler?
12:00weavejesterWell, if you just wanted to check if someone had a full house, then...
12:00SomelauwOh, but I also want to return the fullhouse.
12:00weavejester(and (contains-pair? hand) (contains-three? hand))
12:01weavejesterAh, presumably the highest fullhouse too?
12:01SomelauwSince I want to compare which fullhouse is best.
12:01SomelauwYes, the highest
12:01weavejesterI'd probably split it up into two problems then...
12:02weavejester(defn fullhouse? [hand] (and (pair? hand) (three? hand)))
12:02SomelauwAnd a implicit precondition is that there are no quads in the input of fullhouse.
12:02weavejester(defn highest-fullhouse [hand] (if (fullhouse? hand) (concat (highest-pair hand) (highest-three hand))))
12:02SomelauwBut if there are 3A's and 3J's, a fullhouse can be made by taking only 2 jacks.
12:04weavejesterHm... yes, a 3A 2J beats a 3J 2A
12:04weavejesterSo...
12:05weavejesterMaybe something to take the cards
12:05SomelauwBut a hypothetic highest-pair function will either ignore the 3J's or return the aces.
12:05weavejesterYes, you'd have to use partitioning
12:07weavejesterReally you want a form of state...
12:09SomelauwThe input could consist of 7 cards: 5 on the table and 2 held.
12:09weavejesterHold'em, presumably?
12:09Somelauwyes
12:11Somelauwstate? why?
12:13weavejesterWell, you'd want to ensure that the pair and three are different, but perhaps there's a better way to do that.
12:15weavejesterIt almost feels like a combinations function would be good here.
12:16weavejesterMaybe your function is the best way of doing it. Let me take a look...
12:17SomelauwYou mean trying all permutations of 5 cards? That would probably be slower but work as well.
12:22weavejesterHm... It makes sense to have a (pairs hand) which returns all the valid pairs, and a (threes hand) which returns all valid three of a kinds
12:23bsteuberSomelauw, weavejester: I'd do it like this: https://gist.github.com/1547828
12:23weavejesterSo then the question becomes, do this pair and three overlap or not?
12:23SomelauwIf I make three-of-a-kind return all remainders as well in a map, I could run pair on the remainders.
12:23Somelauwbsteuber: I'll take a look
12:24weavejesterbsteuber: Does that account for the case where you have overlaps, e.g. 3J 3A ?
12:26Somelauwpair would return the highest triple or pair and do (take 2 on the output).
12:26carlos1hello!
12:26weavejesterbsteuber: Yeah, it looks like it might cover all cases
12:26weavejestercarlos1: hello!
12:28carlos1where can I have a good explanation of "when"?
12:29weavejesterI'd be tempted to write a function (defn independent? [xs ys] (empty? (set/intersection (set xs) (set ys))))
12:29Somelauwcarlos1: (doc when)?
12:30weavejestercarlos1: It's like "if" but all the forms after the condition execute in sequence
12:30weavejestercarlos1: So... (when true (println "Hello") (println "World")) would print "Hello" then "World"
12:30carlos1weavejester, but in (when true 1 2 3), only 3 seems to be executed
12:31ordnungswidrigcarlos1: only 3 is returned.
12:31weavejestercarlos1: All are evaluated, but only the last evaluated form is returned from an expression
12:31carlos1ha ok. now everything makes sense. thank you
12:31weavejester(when x y z) is equivalent to (if x (do x y))
12:32ordnungswidrigcarlos1: the REPL can be confusing in this regard. compare (print 1) vs. 1
12:32carlos1it's OK haha
12:33carlos1I understand. just a simple way of make an imperative if
12:40weavejesterSomelauw: Maybe something like https://gist.github.com/1547883
12:41weavejesterThough I'm not sure if the order of the full-houses is correct...
12:43weavejesterMaybe the order should only be calulated at the end with a (sort-by (comp sum rank))
12:46SomelauwI came up with: http://pastebin.com/8dE8Bw49
12:46Somelauwweavejester: I'll take a look
12:48weavejesterJust added an overall-rank function for sorting
12:48Somelauwbsteuber: Thanks for your idea
12:56SomelauwI'm not sure but when determining the overall rank of a fullhouse, I thought first the triples are compared and then the pairs.
12:57yoklovif i wanted a fifo queue in clojure… can I get that? or should i just write my own
12:57SomelauwThanks for helping me
12:57Somelauwafk
12:58tscheiblyokov: clojure.lang.PersistentQueue
12:58tscheiblyokov: you must create an empty one using PersistentQueue/EMPTY
12:58yoklovOh, alright, huh.
13:01tscheiblyokov: look here: http://fiji.sc/javadoc/clojure/lang/PersistentQueue.html ... for some reason they still haven't wrapped it in idiomatic clojure but it's there and I've been using it for some time now
13:01tscheiblyokov: howeer, after creation you can use it like any other collection
13:01tscheiblhowever..
13:02yoklovhm?
13:04tscheiblyoklov: you can use "peek" to get the most recent element you added with "conj" and use "pop" to get a new collection with this element removed
13:05yoklovoh okay, right, no mutation, pop would have to return a new queue
13:05yoklovinstead of just the top value
13:06tscheiblyep
13:06tscheiblit's an immutable persistent collection like the others
13:06yoklovyou know, coming from scheme i thought that wouldn't trip me up as much as it has.
13:08tscheiblmaybe that's the reason why it's still "not officially" in clojure... it feels somewhat awkward
13:09yoklovhaha, maybe. I sorta meant in general though.
13:10yoklovbut yeah, queues are inherently imperative so it sorta makes sense that it would be a weird thing.
13:10tscheiblyoklov: you could also try lamina from ztellman (u find it on github).. it provides a somewhat statefull "channels" based abstraction..
13:11yoklovhm. strange.
13:13yoklovI'm not really looking for more state, to be honest. I think of my scheme (racket) code as typically being fairly stateless but when programming in clojure I tend to realize "oh yeah i'd usually use a set! here"
13:16yoklovOh, you mean for a queue
13:16tscheibluse atoms in these cases... or alter-var-root if you want to change the root binding of vars that don't get changed very often
13:16tscheibl..instead of set! :)
13:17tscheiblyoklov: yeah u could use lamina channels like queues
13:17yoklovOh, it's not a queue of things which need to be done, it's representing some data that when it changes it adds to the front and removes from the end.
13:18yoklovso i think persistent queue is more of what i want.
13:18tscheiblprobably
13:18tscheiblchannels are propably to "heavy weight" for that purpose
13:18yoklovRight
13:21yoklovso atoms are for when a thing needs to change? what are vars for then?
13:21tscheibl.. too ... damn keyboard :p
13:26Vinzenthm, I don't know it too - what's exactly the difference between swap!-ing the atom and altering-var-root?
13:26tscheiblyoklov: changing the root binding of a var generally isn't a very idiomatic practice
13:27tscheibli beleive alter-var-root is primarily accomplished using locks (although I haven't looked at the code) yet
13:28tscheiblatoms use STM which should be better for performance
13:28yoklovoh okay, i thought there was another way of changing a var for some reason.
13:28tscheibl..and you can use atoms everywhere... just bind it to any symbol.. locally scoped or dynamically
13:29carlos1"user=> (new FileReader "source.txt")' opposed with this syntax sugar "user=> (FileReader. "source.txt")" is there any reason for the usage of that shortcut?
13:29Vinzenttscheibl, yeah I also think it's locks, but I'm not sure... Also, strictly speaking, atoms don't use STM, only refs do
13:29Vinzentcarlos1, second is idiomatic
13:30AWizzArdHello technomancy, please have a look into your query windows, thanks :-)
13:30carlos1Vinzent, I would expect that, but I cannot seem to familiarize or find any reason for the decision, which makes it counter intuitive for myself
13:30tscheiblVinzent: why wouldn't they? they have the same semantics as refs?
13:31tscheiblthey just automatically commit
13:31yoklovSo, sorry about all the questions, but what's the relationship between refs and atoms?
13:31yoklovis there any?
13:31tscheiblisn't it?
13:32tscheiblyoklov: you can change multiple refs in one transaction and commit them atomically
13:32yoklovRight, and you can't do that with atoms?
13:33tscheiblatoms just allow you to change their value atomically
13:33yoklovalright.
13:33Vinzentcarlos1, well, it's 3 chars shorter! :) I don't know the details behind this decision, but I'm used to it very quickly
13:34Vinzenttscheibl, I thought STM refers to dosync and transactions, that's why it is software transactional memory :)
13:35carlos1Vinzent. maybe because dot at the end means instantiation, as opposed to dot in the middle which means namespace escalation
13:35yoklovIts really interesting how well integrated concurrency is into clojure. I'm getting into it not for that but because it's a more modern lisp that runs on the jvm which seems quite well thought out, but it's very cool that it has all of these language-level concurrency semantics.
13:35Vinzenttscheibl, and if they just automatically commit, then why the perfomance is higher with atoms?
13:35Vinzenttscheibl, but actually I don't know, maybe you right
13:36tscheiblVinzent: hmm.. you may be right...
13:36tscheiblVinzent: but they have the "retry" semantics in common with refs
13:37tscheiblVinzent: although they obviously don't use STM in the background
13:38tscheiblactually I've still never really found a reason to use refs in my projects...
13:39tscheibl.. atoms always did the job
13:39yoklovare refs the one that maintain a history?
13:41Vinzenttscheibl, yeah, the same for me. I guess I just haven't faced such problems
13:43tscheiblyoklov: changing refs within a dosync creates a local copy of the changed refs and only commits the changes if not one of them was changed in the meantime.. otherwise the transaction retries
13:44tscheibl... it's the same with an atom.. just you don't do it in a dosync
13:44yoklovOh hm, so thats what the ref-history-* functions mean?
13:45tscheibl.. so you can't change multiple atoms synchronously
14:05SomelauwHm, does clojure sort lazily?
14:08AWizzArdSomelauw: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2679
14:08AWizzArdThe sort fn forwards sorting to some eager JVM methods.
14:09AWizzArdSo, sort is not lazy.
14:14SomelauwAWizzArd: okay, thanks
14:37graphbumhowdy..i'm trying to abstact some stuff (a graph library) into a protocol but i hit a roadblock. is anyone willing to hear me out?
14:38Raynes~anyone
14:38clojurebotJust a heads up, you're more likely to get some help if you ask the question you really want the answer to, instead of "does anyone ..."
14:39yoklovis it more idiomatic clojure to use defstruct for a simple data structure to just use a map?
14:40Vinzentdefstruct is kinda deprecated in favor of defrecord
14:40RaynesIt is never idiomatic Clojure to use defstruct. It was generally replaced by records in 1.2. Furthermore, you almost always just want a map.
14:40yoklovi see
14:40yoklovthank you
14:40Raynes"Is there any reason for me to use defrecord?" is a good question to ask.
14:40RaynesYourself, I mean.
14:41RaynesIf the answer isn't technical, then you probably want a map.
14:43AWizzArdIn most cases I want a record. A map is interesting if I want to hold tons of key/value pairs.
14:43AWizzArdAlso records are able to hold any number, like maps. It is only that their access is a few nanoseconds slower.
14:44RaynesWhy create a type for the sake of creating a type?
14:44yoklovwhat benefits does it hold?
14:45AWizzArdIt depends on the situation. If you have a function which just wants to return some data, and it makes sense to return it in a key/value fashion, then a map is perfect.
14:45graphbumhow can a protocol be modified, or properly utilized, account for different constructors? For instance, most operations on immutable structures can be represented as returning "new" structures via some base constructor function. I want to separate the underlying data storage mechanisms for a graph from the abstract operations on a graph (the graph protocol), so that I can create effecient implementations for various graph stru
14:45AWizzArdA record is interesting if you want to have a typed map, and when you know the keys already.
14:45AWizzArdRecords should hold the core data of your application.
14:46graphbumprotocols dispatch on the type of the first arg, so defining something like (make-graph [g nodes arcs]) inside the protocol doesn't quite work, since g might be implemented as a record (currently), but might be an array later
14:47Vinzentgraphbum, you can use kind of factory or multimethods
14:47graphbumis there a significant performance penalty associated with multimethods that non-extended protocols avoid?
14:47AWizzArdyoklov: also records can be used in combination with Protocols.
14:47Raynesyoklov: Here is an excellent flow chart that will help you decide what to use. https://github.com/cemerick/clojure-type-selection-flowchart/raw/master/choosingtypeforms.png
14:48Raynesyoklov: I'd mostly just focus on what it says.
14:48yoklovhaha, alright: regular map
14:49Vinzentgraphbum, yeah they are slower, but does it really matters in your case?
14:51graphbumI have strayed away from using multimethods for high-traffic or performance sensitive calls, so I cannot answer that definitively at the moment
14:53graphbumI've tried sticking with protocols defined inline with defrecords as needed, for both inherent performance and for defining consistent operations
14:55graphbumare there any benchmarks on the performance hits for using multimethods? maybe something similar to Rich Hickey's transients vs. vectors benchmarks?
14:58yoklovgraphbum: err, i'm not really a clojure programmer but that sounds a lot like premature optimization to me.
14:58Vinzentgraphbum, I don't know about benchmarks, but you can use factory protocols like this https://gist.github.com/1548186 if you doubt
15:00graphbumvinzent, thanks. you're swtiching to reificiation to avoid the problem then. that's useful.
15:00Vinzentnp
15:03graphbumyoklov: it's not premature...there are cases, particularly in graph algos, where arrays are ideal. to me, it makes sense to be able to change the underlying representation as neeeded to exploit effeciencies. I'd like to deal with everything as a lazy sequences, but that only goes so far.
15:03yoklovright, i was talking about reluctance to use multimethods
15:04yoklovThat… doesn't have anything to do with seqs, unless i'm misunderstanding something
15:04yoklovWhich is quite possible, as I said, I don't really know clojure.
15:06graphbumyoklov: multimethods pose a design problem as well. the times I have used them, I ended up realizing I'd just defined a protocol (in pieces), but with a guaranteed performance hit. I tend to end up refactoring them into protocols (if I don't need an uber dispatch function).
15:07yoklovthat sounds pretty reasonable.
15:07graphbumyoklov: I shouldn't say problem.
15:10yoklovIs there a way to map over a, err, map?
15:11yoklovso (map #(* % 2) {:a 1 :b 2 :c 3}) => {:a 2 :b 4 :c 6}
15:11graphbumyou're mapping over the vals in the map
15:11yoklovright.
15:11yoklovis there a way to do that?
15:12raekyoklov: one way is (zipmap (keys m) (map f (vals m)))
15:12graphbuma map is a seq of [key val]
15:12graphbumbeat me to punch
15:12Vinzentand the other one is ##(into {} (for [[k v] {:a 1 :b 2 :c 3}] [k (* v 2)]))
15:12lazybot⇒ {:a 2, :c 6, :b 4}
15:12raekanother is (into (empty m) (for [[k v] m] [k (f v)]))
15:13yoklovis the ## just to make the bot eval it?
15:13Vinzentraek, don't know about empty, thanks
15:13Vinzentyoklov, yes
15:13yoklovokay
15:14graphbumthere's also fmap in clojure.contrib.genric.functor
15:14graphbumbut it's getting into other things you probably don't need. I use zipmap most of the time
15:15yoklovhaha, i'll use zipmap i think, after all this isn't haskell :p
15:15graphbumthe fact that it can quite nicely approximate haskell is fascinating (to me)
15:15graphbumthere's a monad lib
15:15yoklovyeah, it's quite pure and has the required laziness
15:17Vinzentit's sad that pattern matching isn't integrated in the language
15:17yoklovright i was gonna say that
15:17yoklovwhich makes porting code much more awkward
15:18yoklovor, i imagine it would.
15:20AWizzArdWell, you could simply include core.match into your Leiningen project.clj file and have pattern matching…
15:20AWizzArdhttps://github.com/clojure/core.match
15:20yoklovI see, I had no clue that existed.
15:21AWizzArdYes, it is just a one-liner away (:
15:22VinzentAWizzArd, yeah, and it's very cool, but if I could use it with all my lets and defns it'd be even more cooler
15:23AWizzArdVinzent: could you give a minimal example of what you would like to do?
15:25VinzentAWizzArd, e.g. define functions like in other functional languages, something like (defn fac ([0] 1) ([n] ...))
15:26graphbumpattern matching in the definition itself
15:26Vinzentyep
15:27graphbumI think that has to do with the choice arity in clojure
15:28graphbumit would be really nice though....
15:28graphbumstill, match is pretty cool
15:29graphbumthanks for linking it AWizzArd
15:29AWizzArdcore.match will do most useful stuff already. And if anyone has good additions that would fit I am sure the original author would like to talk about it.
15:30graphbumthat's in 1.3 ?
15:32Vinzentgraphbum, I believe it works with 1.2 too
15:33VinzentBy the way, is there a way to create project templates in leiningen? So e.g. it'd automatically add midje and core.match to all new projects
15:34VinzentI saw some conversations about this feature on irc...
15:51tscheibl,(map (fn [[k v]] [k (* v 2)]) {:a 1 :b 2 :c 3})
15:51clojurebot([:a 2] [:c 6] [:b 4])
15:52tscheibl,(into {} (map (fn [[k v]] [k (* v 2)]) {:a 1 :b 2 :c 3}))
15:52clojurebot{:a 2, :c 6, :b 4}
15:53tscheiblwhy do you people always use "for"?
15:54graphbumI wondered that too for a while
15:54graphbumin some cases, it's clearer
15:54AWizzArdfor can do map and filter at the same time.
15:54graphbumalthough you dip into a little language to do it
15:54AWizzArdYes, it is a DSL for List Comprehension.
15:55AWizzArdIn that sense map and filter are special cases of reduce.
15:55AWizzArdList Comprehension can do what map and filter offer, but not what reduce can do.
15:55tscheiblhmm I wouldn't consider that clearer
15:56AWizzArdIt only needs to traverse the sequence once, and thus might be more efficient.
15:56romanandregis using a String as a seq of characters a bad idea?
15:56tscheibl.. that's a point .... in case of map AND filter usage
15:56AWizzArdyes
15:57AWizzArdThat “yes” was for tscheibl, not for romanandreg (:
15:58tscheiblromanandreg: nah, seems to be a quite natural approach
15:58tscheibla string is in fact a sequence of characters...
15:58graphbumi think there may be times when you want to use native string ops and java strinb builders (ugh) but the seq approach to manipulating strings is great
15:59romanandregtscheibl: so, <performance wise> it would be acceptable
15:59romanandreg?
15:59romanandregI'm developing a parser combinator library and I'm parsing strings as seqs of characters, that's why I'm asking...
16:00tscheiblromanandreg: If performance is your concern I would test several possible approaches for your application within a (time)
16:00tscheibl.e.g. like Java stringbuf
16:00reiddraperAny ideas how to troubleshoot this error I get when "require"ing one of my namespaces? CompilerException java.lang.VerifyError: (class: knockbox/registers/LWWRegister, method: create signature: (Lclojure/lang/IPersistentMap;)Lknockbox/registers/LWWRegister;) Expecting to find unitialized object on stack, compiling:(knockbox/registers.clj:27)
16:00graphbumgood rule of thumb: go with the obvious seq-influenced route, to get obvious and readable code, then if performance is an issue, spot-optimize with less-general stuff (like string builders etc.)
16:01graphbumif performance ends up not being an issue.. declare victory
16:01romanandreggraphbum: cool… I won't do premature optimizations then :-P (just chillax mode)
16:01graphbumi was messing with a toy problem a while back.
16:01graphbumbased on string stuff
16:02graphbumgot a dictionary of words, like 250K
16:02graphbumin a text file
16:02graphbumdefine the friend of a word w as any other word with levenshtein edit-distance of 1 from
16:02graphbumw
16:03graphbum you can substitute, remove, or add 1 letter
16:03alexbaranoskyreiddraper, I've never seen that error, sorry
16:03graphbumthe social network of a word are the friends of its friends, etc.
16:04graphbumproblem was to find the social network of an arbitrary word in the dictionary
16:04graphbumused strings-as-sequences just like you described
16:04reiddraperalexbaranosky: thanks, google only seems to find one result too...
16:04graphbumnot a big performance problem.
16:05graphbumthen again, I did not go back and optimize using lower-level string operations (did not know enough java at the time, did not want to either).
16:06tscheiblha.. I remember when I started to program in Clojure I used to put typehints almost everywhere (out of performance concerns)....
16:06tscheiblI haven't used a single Typehint now for month now...
16:06tscheibl.. still no performance issues...
16:06graphbumJoy of Clojure had a good section on how typehints can cripple the compiler and hurt performance
16:08tscheiblin essence it's really best to start with the most simpe and general approach and spot optimize if you really hit performance problems (as it already has been said)
16:08graphbumseems like reflection is the enemy of performance, so you want to stamp that out. type-hinting java classes during interop seems to be an obvious case.
16:09reiddraperalexbaranosky: looks like it may be related to this: http://dev.clojure.org/jira/browse/CLJ-837
16:10Okanhello .. i have a problem on clojure emacs-slime lein instalation
16:10Okani install lein in standalone bat file
16:11Okancan anybody help me.. i can share the error Message
16:11OkanDebugger entered--Lisp error: (error #("Could not start swank server:
16:11Okan\"C:\\Users\\OKan Aky】\\.lein\\self-installs\\leiningen-1.6.2-standalone.jar\" can not be found.
16:11OkanYou can try running \"lein self-install\"
16:11Okanor change LEIN_JAR environment variable
16:11Okanor edit lein.bat to set appropriate LEIN_JAR path.
16:11Okan
16:11Okan" 49 253 (charset japanese-jisx0208)))
16:11Okan signal(error (#("Could not start swank server: \n\"C:\\Users\\OKan Aky】\\.lein\\self-installs\\leiningen-1.6.2-standalone.jar\" can not be found.\nYou can try running \"lein self-install\"\nor change LEIN_JAR environment variable\nor edit lein.bat to set appropriate LEIN_JAR path.\n\n" 49 253 (charset japanese-jisx0208))))
16:12Okan error("Could not start swank server: %s" #("\n\"C:\\Users\\OKan Aky】\\.lein\\self-installs\\leiningen-1.6.2-standalone.jar\" can not be found.\nYou can try running \"lein self-install\"\nor change LEIN_JAR environment variable\nor edit lein.bat to set appropriate LEIN_JAR path.\n\n" 19 223 (charset japanese-jisx0208)))
16:12Okan (let ((debug-on-error t)) (error "Could not start swank server: %s" (with-current-buffer ... ...)))
16:12Okan clojure-jack-in-sentinel(#<process swank> "finished\n")
16:12Okan
16:13graphbumOkan: where is leiningen-1.6.2-standalone.jar located on your system?
16:14Okaninside the c:\user\Okan AKyüz\..
16:15graphbumOkan: is LEIN_JAR setup as an environment variable pointing there?
16:15graphbumOkan: or did you modify the path in the .bat file?
16:17Okanthe path is conrect
16:17Okanmy problem is my surname because it is turkish
16:18graphbumOkan: did you run "lein self-install" ?
16:18Okanyes i did
16:19Okanshould i move the file and change any environment setup
16:19graphbumokan: is lein working by itself? can you do "lein repl"
16:20Okani can run under cmd commond
16:20Okani cant reach under emacs with clojure-jack-in
16:21graphbumokan: so lein is working fine
16:22Okangraphbum: lein is fine but swank
16:23graphbumokan: is it possible the characterset is messing with the path?
16:23graphbumokan: or not being parsed properly
16:23Okanactually slime runs ccl common lisp fine too
16:25pmooserHas anyone managed to get colorized stack traces from swank-1.3.4 with just normal M-x slime-connect (as opposed to clojure-jack-in) ?
16:27graphbumokan: sounds like pmooser might be the dude to talk to. I am out of depth.
16:27pmooserWhaa ?
16:29Okangraphbum: i set the home environment and LEIN_JAR environment
16:30Okanmy problem little bit changed
16:31graphbumpmooser: Okan was having trouble getting clojure hooked up in emacs-slime. given the context of your question, I figured you might be able to help.
16:33pmoosergraphbum: It's reasonably challenging … I think the only real path for someone who doesn't use emacs regularly is try to use as much of the magical package.el stuff that technomancy provides to do their setup … As he describes here: http://technomancy.us/149
16:33pmooserI don't have the option for doing that since at work we can't use leiningen, so I still have to figure out how to do things "the manual way", which is generally not straightforward.
16:35Okani set the lein i guess
16:35alexbaranoskyreiddraper, oh that looks very promising...
16:35alexbaranoskyreiddraper, the link that is
16:35Okani add HOME environment c:\lispemacs
16:36reiddraperalexbaranosky: yeah, i had a param called __meta, just changed it to `metad`. I have funcs that wrap the constructors anyway, so it doesn't really matter
16:36graphbumpmooser: I ditched and went with CCW/eclipse just to get functional.....although I have been lured by emacs. It's still a ways off for me.
16:36Okani move the .lein folder which is under my user directory to c:\lispemacs\.lein
16:37Okanafter that i set the LEIN_JAR
16:37Okanenvironment
16:37pmoosergraphbum: Ah, hm. I can't use CCW for myself because its builder is slightly strange (to me) in that it seems to require an open REPL.
16:37Okanthe current problem is swank does not recognize clojure.main()
16:37pmooserI'm actually trying to hack my own clojure builder for eclipse right now, but I know nothing at all about eclipse plugins, and it's not very fun.
16:38graphbumpmooser: yeah, you compile from the repl.
16:38pmoosergraphbum: Yeh, our projects at work are largely java-based and I want a builder that doesn't require people who don't use clojure to know what a REPL is.
16:38graphbumpmooser: eclipse isn't great, but it's decent enough. CCW has gotten better over time. I'm not doing any huge projects though, mostly research software (no teams to deal with).
16:39graphbumpmooser: got it.
16:39pmooserOkan: What do you mean that it does not recognize clojure.main ?
16:39Okanpmooser: error code is changed
16:40OkanDebugger entered--Lisp error: (error "Could not start swank server: java.lang.NoClassDefFoundError: clojure/main
16:40OkanCaused by: java.lang.ClassNotFoundException: clojure.main
16:40Okan at java.net.URLClassLoader$1.run(Unknown Source)
16:40Okan at java.security.AccessController.doPrivileged(Native Method)
16:40Okan at java.net.URLClassLoader.findClass(Unknown Source)
16:40Okan at java.lang.ClassLoader.loadClass(Unknown Source)
16:40reiddraperalexbaranosky: do you know if travi-ci has the lein-midje plugin?
16:40Okan at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
16:40Okan at java.lang.ClassLoader.loadClass(Unknown Source)
16:40OkanCou
16:40pmooserOkan, how are you trying to launch the swank server ?
16:41alexbaranoskyreiddraper, I'v never heard of travi-ci
16:41Okanpmooser: i start lein like lein new prj
16:41Okanpmooser: under the emacs i C-d to change directory
16:41triyoIn leiningen, I'm running `uberjar` and have my own log4j.xml file I wish included. However, my question is what happens when dependency libraries get included with their own log4j.xml files?
16:41reiddraperalexbaranosky: it's a continuous integration service for open source projects, http://travis-ci.org/
16:42Okanand after that clojere-jack-in
16:42triyoSo question is will my own log4j.xml overwrite the lib ones?
16:43pmooserOkan: so you've previously done something like "lein plugin install swank-clojure.1.3.4", and then lein deps ?
16:44pmooserDoes just doing 'lein swank' from the command line work for you ? This certainly won't solve your problem but if you are having class path issues I'm curious if lein swank hits the same issues or not.
16:44Okanpmooser: let me try
16:44triyoAnd if not, can I indicate in project.clj for the dependencies to exclude the log4j.xml file?
16:45alexbaranoskyreiddraper, probably doesn't have the plugin -- what would it take to set travis-ci to have it?
16:46alexbaranoskyreiddraper, do you have any first impressions or feedback on Midje? I like to hear people's reactions to it -- what they like/dislike, what they miss, etc
16:47reiddraperalexbaranosky: actually just including lein-midje in the project.clj might be enough. I'm not sure if it will be able to "interpret" the output though. Maybe it just uses exit code?
16:47reiddraperalexbaranosky: i've only written one test so far, but my first impression is that midje is _very_ well documented
16:50reiddraperalexbaranosky: ever see this in a test? java.lang.Boolean cannot be cast to clojure.lang.IReference
16:53alexbaranoskycalling alter-meta! or reset-meta! on a boolean it sounds like ???
16:53lazybotalexbaranosky: Oh, absolutely.
16:53alexbaranoskyreiddraper, by test do you mean fact?
16:53reiddraperyes
16:53reiddraperalexbaranosky: https://gist.github.com/a550086d332419c55dbc
16:55pmooserOkan, any luck ?
16:56triyoOk it actually seems that leiningen will prefer the resources from my project as oppose to the dependencies resources.
16:57alexbaranoskyreiddraper, I'm not sure what that is
16:57alexbaranoskyreiddraper, does it run fine without the with-test?
16:57reiddraperalexbaranosky: ah, yep
16:57reiddraperhmm
16:58triyoso if I have a log4j.xml file, it will prefer it to the dependency lib one when performing uberjar.
16:59alexbaranoskyreiddraper, I've never used with-test, but looking at the source it seems to expect a body argument to be passed
16:59alexbaranoskyreiddraper, http://clojuredocs.org/clojure_core/clojure.test/with-test
16:59alexbaranoskyreiddraper, and voila with-test uses alter-meta!
17:00alexbaranoskyahhhhhhhhhh the fact is evaluating to false/true
17:00alexbaranoskyand then the macro tries to alter the meta of that
17:00alexbaranoskyreiddraper, and thus the exception you're seeing
17:01reiddraperah, yep, that makes sense. I'll see if I just can't get lein midje to work on travis-ci
17:01reiddraperso i don't have to wrap with with-test
17:02pmooserOK, well, good luck Okan.
17:02alexbaranoskyreiddraper, cool, keep me posted on the travis-ci stuff
17:03wingiewhat systems are clojure a good fit too and why shouldn't i use node.js?
17:04technomancywingie: evented IO is really only appropriate for a very small set of computationally-nonintensive problems
17:06edbondSomeone has example of using gloss with files?
17:10dnolenwingie: Clojure is a general purpose programming language. It's good for pretty much anything. JVM startup time makes it less than ideal for simple scripting. But you could of course compile to JS w/ ClojureScript and target node.js for that ;)
17:11yoklovwhat is the equivalent of progn or begin (in other lisps) for clojure?
17:12yoklov(those do a bunch of things in order.)
17:12dnolenyoklov: do
17:12yoklovah, thanks.
17:14wingiednolen: i read about clojurescript .. is it considered ready?
17:16wingietechnomancy: what intense task would be a good fit for clojure? (can't find anything for me to test it with since im using node.js for web stuff)
17:18technomancywingie: the evented approach is well-suited for tasks that consist of just routing traffic from one socket to another. everything else needs more flexibility.
17:19wingietechnomancy: yeah im using it as web backend between web app and db
17:19wingiebut cant figure out what else i would need
17:20wingieperhaps i have no need for clojure yet
17:20wingiebut i wanna use it for something :)
17:22dnolenwingie: it's alpha, but it's already useful.
17:23wingiednolen: the only reason for using it would be the scripting flexibility since java has a long start time?
17:23dnolenwingie: clojure is equally suited for web stuff. IMHO Clojure is a superior language over JavaScript (and I've been doing JS for a long time)
17:24dnolenwingie: yes
17:25wingiednolen: yeah it seems very capable
17:26wingieand you learn a lot about proper programming
17:26wingieyou could easily generate bad code in js
17:26wingiecs (coffeescript) helps a little
17:28dnolenwingie: you can generate bad code in Clojure as well. But I think Clojure has saner, simpler semantics and a richer feature set.
17:28wingiednolen: it just seems that when i read js book they don't talk as much about proper coding
17:29wingiewhy i wanna learn clojure's fp
17:30reiddraperalexbaranosky: got it working, http://travis-ci.org/#!/reiddraper/knockbox
17:31alexbaranoskyreiddraper, that's really cool, I'll have to check out travis-ci sometime
18:00wingieshould impure functions be tested too?
18:01amalloy"should x be tested" => yes for all x
18:01technomancyimpure functions need a lot more tests than pure ones
18:23yoklovHrm, should ``for'' be able to iterate over sets?
18:23yoklovCrap, nevermind.
19:23yoklovyes! my code works now!
19:23yoklovhttps://gist.github.com/1548720
19:24yoklovis that code, uh, good style for clojure code?
19:25yoklovi feel like i am swap!ing too many things
19:25scottjyoklov: alignment formatting is uncommon and would be a burden for other people to maintain.
19:26yoklovalignment formatting?
19:26amalloyyoklov: your let bindings have the valeus lined up
19:26scottj(def foo {:bar...) too
19:26yoklovoh, right
19:26amalloya style i mostly don't care for, but i do have a hacked version of align-let.el that works on clojure's let
19:27yoklovhm, thats sorta a thing i do in almost all code i write
19:27yoklovIt's uncommon in clojure?
19:27scottjhttps://github.com/scottjad/align-cljlet
19:28scottjadds align-map and align-defroutes
19:29amalloyyoklov: i mostly like the approach, and it seems like you're making an effort to minimize mutable state
19:29amalloyor localize it, at least
19:29yoklovyeah
19:29scottjactually origin looks better now https://github.com/gstamp/align-cljlet (except align-defroutes)
19:30amalloybut you don't need the food/snake atoms at all - you can have tick return a food/snake pair instead of modifying the atoms
19:30yoklovi just use align-regex usually
19:30yoklovreally?
19:30yoklovhm
19:31yoklovbut then i'd have to change the key-event to work differently
19:31yoklovand the drawing
19:31yoklovwhich I couldn't figure out how to do so i went with mutating the atoms
19:32amalloywell, fair enough
19:32yoklovwell no, i'd love to ditch the atoms, if you can suggest the way to have that not happen.
19:33amalloybecause you need it to work in paint(), you do need at least one atom somewhere. my preference would probably be to have that atom be a map (or pair) of snake/food, and deref it before you pass it into anything but paint
19:33yoklovand swap it after tick?
19:34yoklovthat still doesn't really handle the keypress though
19:37amalloywe've made the whole world into a single atom; it's easy for keypress to change the direction
19:38amalloyalso, the way you're using @ and swap! a million times in a single function is not safe at all. if this code were actually called from multiple threads you'd quickly lose integrity. it won't be, because swing only calls you from the dispatch thread
19:39amalloybut if you make the whole world an atom, and then swap! it with a single function that makes all the necessary changes, that problem disappears as well
19:39yoklovi see.
19:41reiddraperalexbaranosky: are there any examples of programmatically generating tests in midje?
19:47alexbaranoskyreiddraper, what do mean exactly by programmatically?
19:47alexbaranoskyyou could use `tabular` or a macro
19:49reiddraperalexbaranosky: I've got some test I'd like to test on some list of input, and i'd like to see them pass/fail separately. looking at tabular now
19:49alexbaranoskytabular sounds like what you want
19:49alexbaranoskyit will give you sane output, letting you know which example failed
19:50reiddraperdo you have any examples of generating tests with macros?
19:50reiddraperi'm kind of a macro noob
19:50alexbaranoskynope, I never use them, tabular always does what I want :)
19:51reiddraperalexbaranosky: thanks
19:51alexbaranoskytabular is 'basically' a macro that makes a fact for each row of the table
19:52reiddrapercool, it's looking like what I want
20:00reiddraperalexbaranosky: any way i can use (let) in tabular?
20:02alexbaranoskyhave you tried it?
20:02alexbaranoskyyou can always (I think) wrap the whole tabular form in a let
20:03reiddrapergot it figured out, i was accidently including the table in my let sexp
20:06alexbaranoskya set-based Game of Life implementation: https://github.com/AlexBaranosky/GameOfLife/blob/master/src/retreat1/core.clj
20:07alexbaranoskywhere the 'cells' are people
20:10mrb_bkdnolen: playing with core.match, it's a lot of fun
20:14alexbaranoskyreiddraper, I"m looking forward to see a proposal of what quickcheck-like testing via Midje might look like
20:15reiddraperalexbaranosky: cool. I need to give it some more thought, and play with the Erlang implementation more
20:15reiddraperbut will do
20:17alexbaranoskyreiddraper, in general I really like to hear feedback on what works/sucks/is-missing from Midje - it helps me think about improvements
20:18reiddraperalexbaranosky: Great. I'm sure I'll have more opinions once I've used it a bit more
20:36yoklovalright
20:36yoklovonly one atom now
20:36yoklovhttps://gist.github.com/1548720
20:37technomancyalexbaranosky: are you leading up the development of midje these days?
20:37yoklovif anybody has any suggestions on how to make that code any better, i'm very interested :)
20:38alexbaranoskytechnomancy, It's basically me and Brian Marick, but Marick's really busy and doesn't do as much as he did in the past
20:38technomancysure
20:41reiddraperanyone using deftype find themselves having to use `lein clean` to get new code to run, even without AOT?
20:41wiseenCan someone help me figure out how to invoke this function http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html#register(java.nio.file.WatchService, java.nio.file.WatchEvent.Kind...) ?
20:41wiseenI keep getting java.lang.IllegalArgumentException: No matching method found: register for class sun.nio.fs.UnixPath
20:41amalloywhy do you have count in your main-loop at all? you never use it
20:43yoklovoh, thats let over from debugging
20:43amalloyit seems to me it would also lead to nicer code if you represented x/y coordinates as a [y x] pair (or i guess [x y] if you prefer) instead of having to do all this pulling-apart and rebuilding of an x/y map
20:43yoklovi uh, forgot it was there, to be honest
20:43yoklovhm
20:43yoklovthats a good point
20:43wiseenI tried : (.register dir service (into-array WatchEvent/Kind [StandardWatchEventKinds/ENTRY_CREATE StandardWatchEventKinds/ENTRY_DELETE StandardWatchEventKinds/ENTRY_MODIFY])) and simply passing event kinds as varargs but each time I get the exception
20:43amalloyfor example, you could do stuff like ##(let [north [-1 0], pos [8 3]] (map + north pos))
20:43lazybot⇒ (7 3)
20:44amalloyand write [(dec y) x] instead of {:x x :y (dec y)}
20:45amalloy(case (rand-int 4) 0 :n, 1 :s, 2 :e, 3 :w) => ([:n :s :e :w] (rand-int 4)), fwiw. nitpicky stuff
20:45yoklovyeah, i'm sort of blown away by (map +) haha
20:46amalloyyoklov: you can use a similar map trick to do bounds-checking
20:47yoklovsomething like (map < [0 0] [x y] [width height])?
20:48amalloyright
20:48amalloyhttps://gist.github.com/1548959 is a snippet from one of my 4clojure solutions using that technique
20:50yoklovthats very clever
20:52alexbaranoskywiseen, I think the problem might the overloaded method
20:54wiseenalexbaranosky, yeah but how do I tried to add a dummy argument for the second overload : nil and (into-array WatchEvent/Modifier [])
20:54wiseenstill get the exception
20:55wiseenis there a way to specify the overload explicitly ?
20:55alexbaranoskywiseen, I saw a solution to this issue a while back, but cfan't recall it
20:56alexbaranoskyI distinctly recall cemerick had the solution, but he isn't online now
20:57alexbaranoskywiseen, maybe this'll help http://stackoverflow.com/questions/2722856/how-do-i-call-overloaded-java-methods-in-clojure
20:58wiseenalexbaranosky, saw that :) it's about boxing - that doesn't seem to be my problem since none of the types I'm passing to the function are value types
20:58amalloywiseen: WatchEvent/Kind shouldn't be a valid thing. you mean WatchEvent$Kind?
20:58wiseenamalloy, nope , let me try that
21:01wiseenamalloy, tnx. that fixed it
21:01amalloytbh i don't know how WatchEvent/Kind compiled at all
21:01wiseenyeah, just goign to say that, it didn't complain about that
22:43graphbumis there an idiomatic way to serialize a record?
22:43graphbumas a string that can be evaluated with (read-str)
22:43amalloyuse 1.3
22:43graphbumerr read-string
22:45graphbumdo the record structures just "work" in 1.3? if I (= myrecord (read-string (print-dup myrecord))) evals to true?
22:47amalloyyes
22:47amalloythough i don't know why you're calling print-dup instead of just pr-str
22:48graphbumbecause I am ignorant
22:49graphbumand behind on versions
22:49graphbumthanks
23:12lnostdal... :( sometimes all this cool stuff seems worthless when core stuff doesn't work .. stack-traces that doesn't make sense or even end up outside the debugger because heaven-forbid you're using futures or agents or whatever -- with no stack-frame data for variables etc. ..
23:16graphbumI haven't been screwed over by agents yet, but I haven't been using them too much. I hear you on the funky stack traces.....you develop a sixth sense about what errors "really" mean for some things.
23:26bitopshi all, clojure newcomer here - I'm playing around at the repl but having some trouble requiring libraries. If I plug in the code at the top of http://richhickey.github.com/clojure-contrib/generic.math-functions-api.html#clojure.contrib.generic.math-functions/pow I get an error. I'm using Clojure 1.3 if that's any help.
23:26lazybotNooooo, that's so out of date! Please see instead http://clojure.github.com/clojure-contrib/generic.math-functions-api.html#clojure.contrib.generic.math-functions/pow and try to stop linking to rich's repo.
23:27bitopshaha
23:27bitopsit's unfortunate that rich's repo is at the top of google...
23:30bitopshm…after looking at the pages, maybe I should change my question.
23:30bitopshow do I call the power function? I want to raise some number to another number.
23:30technomancy,(Math/pow 12 3)
23:30clojurebot1728.0
23:31bitopstechnomancy: there's no Clojure pow function?
23:37n0inewp, alot of basic stuff like that is still missing from core.. have to go to java for it or write your own
23:38graphbumor wrap it
23:39bitopsno biggie
23:39bitopsit's actually pretty fun to wrap stuff up…learning a lot
23:39graphbumI actually went quite a while without running into that, until I sat flabbergasted at one point (trying to write a simulated annealing function) and I couldn't find exp
23:40amalloy"still missing" in the sense that there's no real reason to write it. in a hosted language there's really no reason to write strlen again, for example
23:40technomancyamalloy: welllll
23:40technomancyMath/pow only returns doubles
23:40technomancywhich is why generic-math was written
23:40graphbumno ratios
23:40amalloyyeah, i agree having a real exp would be nice
23:41amalloybut to say that there's "a lot" of stuff that's "still missing" overstates the case
23:41graphbumbasic stuff....which requires delegation to the host language
23:44amalloybtw technomancy, the way i found the apt package: $ apt-file find -x completion.*git
23:45bitopsI suppose one could argue that Clojure sort of encourages you to delegate to JavaLand - lots of neat stuff to use there.
23:46bitopsoh, but I'm reminded, so….what's the best way to require stuff? Looking at http://dev.clojure.org/display/doc/Clojure+Contrib it seems much has changed?
23:47bitopsfair to assume that everything in core is auto-required on repl load?
23:52technomancybitops: all of the clojure.core namespace, yeah
23:53bitopstechnomancy: that makes sense - I'll be darned if I can require numeric tower though
23:54bitops(require '[clojure.math.numeric-tower]) ;; is incorrect?
23:57bitops…..anyone?….. :)
23:57technomancythat should work if it's in your project.clj
23:57graphbumbitops, how are you running your repl?
23:58bitopsgraphbum: I'm just starting it via rlwrap java -cp /Users/sebastian/bin/clojure-1.3.0/clojure.jar clojure.main
23:59bitops(rlwrap just for line editing)
23:59bitopstechnomancy: I'm not running in a lein project
23:59bitopsjust plain old repl
23:59bitopsdoes that make the difference?