#clojure logs

2011-01-26

03:06TobiasRaedermorning
03:12Scriptormorning TobiasRaeder
05:28edoloughlinI keep getting a notice from sexpbot saying I have a new message and should 'use the mymail or mail commands without'. Excuse my ignorance, but what on Earth is this?
05:31mrBliss`edoloughlin: have a look at https://github.com/Raynes/sexpbot/blob/master/src/sexpbot/plugins/mail.clj
05:33edoloughlinmrBliss: Sorry, I've been a developer since 1992 but never used IRC for whatever reason until I started using Clojure. How do I send a command to sexpbot?
05:35mrBliss`edoloughlin: I think it is "/query sexpbot", but I'm not sure.
05:35edoloughlinThanks
06:01LeonidasI have a global configuration (immutable) that I want to read from a JSON file and access in all functions. what is the best way to handle this? global variable? parameter to each function? a dynamically bound variable?
06:09ejacksonLeonidas: I think a dynamically bound variable is the accepted answer, but not sure.
06:10Leonidasejackson: I am thinking about posting it on the mailing list as it is not a technical problem but rather one of various pros and cons.
06:10ejacksonI think if you search the IRC logs first, you'll find this discussed before
06:11clgvLeonidas: I made a configuration Object but also played with the thought of dynamically bound variables
06:11ejacksonin fact, I'm almost certain of it
06:11Leonidasejackson: the problem is, I don't know the proper search terms to get any useful results
06:39AWizzArd~seen rhickey
06:39clojurebotPardon?
06:39AWizzArd$seen rhickey
06:39sexpbotrhickey was last seen quitting 2 weeks and 1 day ago.
06:43ejacksonsexpbot: rhickey is not a quitter - how DARE YOU SIR !
06:49clgvlol!
07:05Leonidashttp://paste.pocoo.org/show/327135/ why does this fail in json-read? I thought json-read returns the value when encountering an EOF?
07:08clgvA tricky question: when I open a repl in code that runs in the java Swing GUI thread I get an exeption that I am not allowed to use (in-ns) - does someone know why?
07:09clgvit's the debug-repl of George Jahad and Alex Osborne
07:09raekare you running a repl session in the swing thread?
07:09raekwon't that block all gui events?
07:18clgvyes it will. it is a debug-repl to see why certain GUI code fails ;)
07:19Leonidasfun, I ran into a read-json bug
07:19Leonidashttp://dev.clojure.org/jira/browse/CONTRIB-99
07:19clgvit works in general but I cant change the namespace to the surrounding ns of the macro with (in-ns)
07:25clgvThe exceptions says: Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set
07:25raekI though that bug had been fixed
07:25raekhttp://dev.clojure.org/jira/browse/CONTRIB-91
07:30raekthere is a patch for it, but maybe it never got in...
08:26Leonidasget-votes-and-filter (fn [line] (remove (fn [[k v]] false) (get-votes line)))
08:26Leonidasthis always fails with clojure.lang.LazySeq cannot be cast to clojure.lang.Associative. Why?
08:26Leonidasthe remove-call should be a no-op
08:29timvisherhi all
08:30AWizzArdHi timvisher.
08:32timvisheris there an easy way to write compound filters? i.e. (filter (and #(.isFile %) (complement #(.isHidden %))) ...)
08:33timvisherpossibly even a filter that works on a #{} of predicates?
08:35l0st3dtimvisher: as in (filter #(and (.isFile %) (not (.isHidden %))) ...) ?
08:36timvisherl0st3d: you know, I had a tickling feeling at the back of my skull that all I'd have to do was make the whole and a function...
08:37timvisherthanks!
08:37timvisherstill new at this. :)
08:37Leonidas(fn [line] (remove (fn [[k v]] false) (get-votes line))) why does calling this result in a clojure.lang.LazySeq cannot be cast to clojure.lang.Associative error?
08:37l0st3dtimvisher: me too ;)
08:38clgvtimvisher: though a (filter-all #{ .isHidden isFile } ...) would be nice too ;)
08:38l0st3dtimvisher: there's something called comp that will compose fns for you
08:38clgvs/#{ .isHidden isFile }/[.isHidden .isFile]/
08:43raekLeonidas: what happens if you just eval (get-votes line)?
08:44Leonidasraek: {"Foo" {:upvotes 0 :downvotes 1}}
08:45Leonidasstrange things happen
08:45raek,(fn [] (remove (fn [[k v]] false) {"Foo" {:upvotes 0 :downvotes 1}}))
08:45clojurebot#<sandbox$eval628$fn__629 sandbox$eval628$fn__629@e5590e>
08:45raek,(remove (fn [[k v]] false) {"Foo" {:upvotes 0 :downvotes 1}})
08:45clojurebot(["Foo" {:upvotes 0, :downvotes 1}])
08:46raekI think the problem is somewhere else..
08:46Leonidasyeah, there is a [ ] there
08:46Leonidaswhere does the vector in the result come from?
08:47raekit's actually a MapEntry
08:47raekthey implement IPersistentVector
08:47raek,(seq {:a 1, :b 2})
08:47clojurebot([:a 1] [:b 2])
08:47LeonidasI wanted to remove items which fail a certain perdicate from a dict, but what remove does is something... else.
08:48Leonidasis there a way how I can get a map out?
08:48raek,(let [m {:a 1, :b 2}] (into (empty m) (remove (fn [[_ v]] (odd? v)) m)))
08:48clojurebot{:b 2}
08:49raekthis will also the preserve the map type (hash-map/sorted-map)
08:50Leonidaswhat is the point of this strange behaviour?
08:51raekwhat behaviour?
08:51raekremove operates on sequences. it automatically calls seq on its argument to get a sequence for it.
08:52Leonidasthat mapentries get generated? I thought that when I 'remove' on a map I get a map of the same shape out
08:52raekit could be possible that they are the same map enties used internally in the map
08:53raekconj, into, disj, pop, peek are polymorphic and return a datastructure of the same kind
08:53raekthe sequence functions are seq-in seq-out
08:54Leonidasah, hmm, I see. Much I have to learn, still
08:56raek(seq x) for data structure -> sequence and (into (empty x) ...) for sequence -> data structure lets you use the same functions for any type
08:58zippy314Hi, I'm looking on thoughts on best practices in Clojure for handling inheritance. I've been reading The Joy of Clojure on prototyping and UDP, and I've implemented a few protocols/records. What I think I'd like to do is create a record/type that mixes in new methods, and can itself be inherited from. But I'm wondering if anybody have any pointers to best-practices/idiomatic ways of doing this in clojure?
09:02ejacksonzippy314: i don't think it can be done. I tried before and ended up using macros to kludge it. However the more skilled present may know otherwise.
09:03clgvzippy314: afaik there is no such thing as inheritance between types or records in clojure.
09:04zippy314cigv: ejackson: is that because it shouldn't be done in clojure because there's a better way to accomplish the same functionality, or because it's a limitation of clojure? That's what I'm trying to figure out.
09:05ejacksonah, its not possible in clojure, deliberately I think.
09:06zippy314I'm reading in the docs this: "Concrete derivation is bad" (http://clojure.org/datatypes) and I'm trying to wrap my head around that.
09:06zippy314and also this "Tying polymorphism to inheritance is bad"
09:07clgvin general you can use a written function on every data that has the "attributes" that are need by the function
09:08timvisheri'm getting a weird issue when I try to run `lein test`.
09:08clgvyou can do dispatch via multimethods
09:08timvisherit's saying that `to-file-name-suffix` cannot be resolved
09:08zippy314Yah. It looks like since you can simply define a record based on multiple protocols, that you can get the same effect just by mixing in lots of interfaces into one record.
09:08timvisherbut `to-file-name-suffix` occurs nowhere in the code
09:09timvisherit used to, but I recently renamed it
09:09zippy314timvisher: you might need to do 'lein clean'
09:09timvisherzippy314: just had that idea. tried it and it didn't make a difference
09:10raekmaybe ~ files lying around
09:10zippy314timvisher: also, maybe unsaved file so your search works, but on disk it's different
09:11timvisherAh!
09:11timvisherI'm i'm an idiot as usual
09:11timvisherthe core.clj file the error is referring to is my now _stale_ test/core.clj
09:11timvisher:)
09:11timvisherthanks as always, everyone
09:25no_mindwhich is a good tutorial for starting web development with clojure ?
09:26dnolenno_mind: http://mmcgrana.github.com/2010/03/clojure-web-development-ring.html
09:26no_mindthnxs
09:35no_mindwhen I run lein deps , it downloads clojure and clojure-contrib forr every new project. is there a way I can avoid this ?
09:36jkdufairI'm a longtime emacs user and have some decent exposure to clojure. I'm on windows and want to set up a production grade development env with Emacs/swank/lein. Recommendations re: native vs. cygwin?
09:36ejacksonhmm, I thought it would pull them from your ~/.m2
09:37ejacksonjkdufair: I did this, but was painful. I used the powershell for lein etc, and normal emacs. I think cygwin should work too, but I had COM stuff in the mix that prevented me from doing it.
09:38jkdufairejackson: thx. i'm leaning toward cygwin and have had some success so far, but just a bit of weirdness with lein
09:39ejacksonyes, that's where I spent most of my time gnashing my teeth. There is a port for the script to powershell which worked fine.
09:39ejacksonif maven works I'd suggest you just use that
09:40jkdufairyou prefer maven over lein?
09:40ejacksonyeah
09:40jkdufairpros/cons?
09:40ejacksonmaven has plugins for a bunch of stuff that i do and integrates nicely with my CI
09:41jkdufaircool. thx
09:41ejacksonthe XML is a pain intially, but nothing dramatic.
09:50shortlordI have written 2 functions and now want to use them from another namespace. Both functions use a lookup table as an argument, this lookup table is defined in their namespace. What is the most functional way to use these 2 functions now? using both functions + the lookup tables and always passing these tables in other namespaces sounds like a bad idea. Should I make some light wrappers in the original namespaces that supply th
09:50shortlorde lookups automatically?
09:54ejacksonshortlord: I dunno why passing the lookup is a bad idea. But, if you arrange your argument order correctly you could partial over the lookup tables perhaps ?
09:54ejacksonfor you wrapper that is
09:54tonylcan you just require the ns where your fns and lookup tables in the current ns you want to use them?
09:54shortlordejackson: yep, building the wrapper is easy, the lookup table is the first argument
09:55ejacksonwell, that seems reasonable, i guess.
09:56shortlordtonyl, ejackson: well, my problem is this: When should I use a wrapper/closure and when should I supply all the arguments every time? I'm pretty sure that the lookup table won't change for the whole application, but just wrapping the function does not seem to be very functional/pure
09:57shortlordI could of course just use the functions without a wrapper, but that would mean that I'd need to pass more arguments every time that I call such a function
09:57ejacksonI think a partially applied function is very functional indeed
09:58tonylthen i agree with ejackson, it seems that that would benefit you
09:59shortlordejackson: so where should I put this partial function? just defn a function in the namespace that uses the original function with the same name and just a (partial lookup-table old-function)?
09:59ejacksonyeah
09:59shortlordor should I put this wrapper function in the old namespace, where both lookup tables and functions are contained?
10:00ejacksonsorry, the latter. put it in the original namespace
10:00shortlordejackson: ok. Is there any standard name scheme for simple wrapper functions? like wrapped-<function-name> or something like that?
10:01ejacksonno, I'd go with something like standard
10:01ejacksonstandard-<function>
10:01ejacksonof default-<function>
10:01ejacksonbut there is no reason to suspect that this is in any way more than my own opinion
10:04shortlordejackson: ok, thx a lot :)
10:14shortlordis it possible to use something like :as in the namespace definition to rename functions in a :use expr? like (:use [clojure.set :only (difference :as diff)])?
10:15mattmitchellanyone know a nice way to convert a hash-map with string values to keyword values?
10:15ChousukeI think you need another vector
10:15Chousukeie. :only ([difference :as diff])
10:16Chousukebut I'm not sure, so check the docstring on use
10:17Chousukemattmitchell: (into {} (map (fn [[k v]] [(keyword k) v]) original-map)) is probably the shortest way without any extra functions.
10:18mattmitchellChousuke: excellent thanks!
10:18Chousukenote though that that may produce illegal keywords
10:18Chousukeif the strings have spaces in them for example
10:19Chousukeif you have string keys, it's often best to just keep them that way :)
10:20mattmitchellChousuke: yes ok. the values are coming from a yaml file, so always come in as strings but will only ever be valid keywords
10:26momosHello. How to check / modify classpath in clojure?I'm trying to write a cake task which uses my project dependent jar's, but my normally working code fails to import java dependencies. How to debug this?
10:28mattmitchellHow can I make a "public" defonce or def? I'd like my other namespaces to have access to this value.
10:29tonyldef is public
10:29tonyljust either require the namespace where the binding is
10:30tonylrequire or use whichever form fits you best
10:30mattmitchelltonyl: oh i see. so i can't just go into a diff namespace and call the other like (other/some-def) ?
10:31mattmitchelltonyl: ahh ok i got it! it's not a function :)
10:31mattmitchelltonyl: thanks
10:32tonylyes, and it could be a function or a special case in the ns form whichever you prefer
10:32mattmitchelltonyl: ok i see
10:35LauJensenChousuke: I prefer reduce ##(reduce #(assoc %1 (keyword (%2 0)) (%2 1)) {} {"string" 5 "str" 10})
10:35sexpbot⟹ {:str 10, :string 5}
10:59symuynLet's say that I have a map: string keys → vectors of string keys.
11:00symuynSo it represents a directed network, and loops are allowed. If a vector contains a string A, the vector’s own key is connected *to* A.
11:00symuynI want to create another map: string keys → sets of string keys, such that the sets only contain all of the string keys that are directly connected to it (but not from it)…including the key itself.
11:00symuyn(Eventually, I’d like to be able to calculate the keys’ distances too, but that can be later.)
11:00symuynI can't think of a good way to start, though. Is there a library or simple function that can help me?
11:01ejacksondoes to-from make any sense in an looping network ?
11:01symuynI believe so
11:01symuynThink of recursive functions
11:01ejacksonA -> B -> C -> A
11:02ejacksonis C connected to or from A ?
11:02symuynOh dear, I think I typoed: "If a vector contains a string A, the vector’s own key is connected *from* A."
11:02ejacksonwell, both
11:02symuynHmm
11:02symuynejackson: Yes, both. Which it will always be, in a loop
11:03hoggarthsymuyn: does this help? http://richhickey.github.com/clojure-contrib/graph-api.html
11:04symuynhoggarth: Do you know the data format that the library's graphs are supposed to be in? I can't find it.
11:04symuynHow do you make a graph?
11:05ejacksonsymuyn: this might throw you off course, but I made a little dijstra toy algo last year. https://github.com/ejackson/dijkstra/blob/master/src/main/clojure/net/edmundjackson/astar.clj It makes graph, connects nodes etc, might be helpful. </end blowing own's trumpet>
11:06hoggarth :nodes ; The nodes of the graph, a collection
11:06hoggarth :neighbors)
11:06hoggarthoops
11:06hoggarthsymuyn: (defstruct directed-graph
11:06hoggarth :nodes ; The nodes of the graph, a collection
11:06hoggarth :neighbors)
11:06symuynhoggarth: I see, a struct.
11:06symuynPity it doesn't show up on the documentation.
11:06symuynejackson: I'll look at that, thanks
11:06mec_Is there a good way to filter for unique values while keeping the sequence in order?
11:06ejacksonof course, cgrand has one too: http://clj-me.cgrand.net/
11:07tonylmec_: has it happened to you otherwise?
11:08chouser(doc distinct)
11:08clojurebot"([coll]); Returns a lazy sequence of the elements of coll with duplicates removed"
11:08chousermec_: ^^^
11:08tonylbut if you want unique values, maybe hash-set's or sorted-sets' would work for you
11:09mec_yes but they need to remain the way they are ordered, sets will change order
11:09mec_chouser: thanks a bunch
11:09ejacksondistinct ! cool.
11:10symuynhoggarth: Yes, this will do; I can't use the library directly, but it shows me how
11:10symuynThanks a lot
11:10mec_i seem to always pick the wrong synonym for what i want
11:11chousermec_: note that if you walk to the end of the seq returned by distinct, you will end up with the whole (non-dup) collection in memory, even if you aren't holding the head of the seq
11:12shortlordthere is no built-in operator that does the opposite of 'frequencies', so (map #(repeat (val %) (key %)) my-map) would be the easiest way, right?
11:12shortlord(+ a flatten in front of it)
11:13mec_chouser: that should be fine
11:14symuynWhat is the hash code of a lazy sequence? What happens when it's used as a hash map's key?
11:16tonyl&(hash (range))
11:16sexpbotExecution Timed Out!
11:16tonylmm good quesiton
11:16tonyl*question
11:18symuynSeems kind of weird
11:19tonylnot necessarily it needs to know the values of the lazy-seq to make a hash of it, so the values are trying to be realized
11:19chousershortlord: mapcat instead of map
11:20symuyn&(count (assoc {} (range) 1 (range) 2))
11:20sexpbotExecution Timed Out!
11:20symuynSo it tries to fully evaluate
11:21tonylyes, that is my understanding of hashcode in java, but it's been a while
11:21chousera lazy seq hashes to the same as a list or vector with the same contents, so it has to realize the whole thing
11:22shortlordchouser: how would mapcat help there? It is only one map that I want to transform into one seq
11:22chousershortlord: then you don't need the flatten or a concat
11:25shortlordchouser: you mean like (mapcat repeat (vals foo) (keys foo))?
11:27chousersure, or (mapcat #(repeat (val %) (key %)) foo)
11:27shortlordchouser: nice solution, thx
11:28chouserI dislike flatten, and (apply concat (map ...)) always suggests (mapcat ...)
11:30symuynflatten does seem a little inefficient
11:31chouserwell, it's a big hammer
11:31chouser,(mapcat #(repeat (val %) (key %)) {:a 2 :b 2 [:c :d] 3})
11:31clojurebot(:a :a :b :b [:c :d] [:c :d] [:c :d])
11:31chouser,(flatten (map #(repeat (val %) (key %)) {:a 2 :b 2 [:c :d] 3}))
11:31clojurebot(:a :a :b :b :c :d :c :d :c :d)
11:32chouserif it's actually what you want, fine, but in my experience it rarely is.
11:38pdk(doc xor)
11:38clojurebotGabh mo leithscéal?
11:38chouser(doc bit-xor)
11:38clojurebot"([x y]); Bitwise exclusive or"
11:39pdki was thinking logical xor to use alongside or/and but hey
11:40chouseryeah, I don't think Clojure's got that
11:40pdkfunky
11:41chouserit couldn't short-circuit or do anything useful varargs like or/and
11:51zippy314is there a way to give defrecord a doc string so that it will show up in autodoc?
11:54tonylzippy314: AFAIK there isn't
11:54zippy314hmmm gripe.
11:56mec_,(str (doall (range 10)))
11:56clojurebot"clojure.lang.LazySeq@9ebadac6"
11:57chouserzippy314: usually the public face of a defrecord is a factory function, which can of course have a docstring
11:57chouser,(pr-str (range 10))
11:57clojurebot"(0 1 2 3 4 5 6 7 8 9)"
11:57zippy314chouser: right!
11:58mec_ah that works, but what am i thinking wrong about doall?
11:59chouserstr and pr-str do the same thing in a lot of cases. strings and lazy-seqs are a couple of the relatively few exceptions
11:59chouser,((juxt str pr-str) [1 2 [3 4] '(5 6)])
11:59clojurebot["[1 2 [3 4] (5 6)]" "[1 2 [3 4] (5 6)]"]
11:59chouser,((juxt str pr-str) "hi")
11:59clojurebot["hi" "\"hi\""]
12:00pdkis there a way to capture a full java stack trace say to a file
12:00pdkvs having it print to the command line and get cut off
12:03zakwilsondanlarkin: that NoSQL presentation you posted last night was interesting. When put in the terms the presented used, it seems likely that I do have a single question I usually want to answer and Mongo is probably a good fit for the problem.
12:03tonylmaybe binding *err* to a reify'ed PrintWriter and change the method that outputs to write to a file
12:03zakwilsons/presended/presenter
12:04tonylpdk: ^^ just the first thought that came to me
12:04tonylso it might be wrong
12:04zippy314pdk: (binding [*err* (java.io.PrintWriter. (writer "/your/file"))]
12:05danlarkinzakwilson: cool, I'm glad you found some value from it, and glad you've come to an evidence-based conclusion :)
12:05tonylsimpler zippy314
12:05zippy314:pdk, then (.printStackTrace e *err*)
12:06zakwilsonAnd if I'm lucky, scaling will be a concern.
12:06symuynAnother question! Pre- and post-condition are idiomatic, and that Clojure style guides says they're supposed to be ubiquitous.
12:06symuynIs there any way to turn them off, though?
12:07symuyn(When you're not debugging, for production runs)
12:10mattmitchellis it possible to "use" namespace B in namespace A, then from namespace C, access the B functions "through" A?
12:12ohpauleezmattmitchell: Take a look at potemkin
12:13ohpauleezTypically, what you're asking for you wouldn't do, but potemkin allows you to man-handle the namespaces and imports
12:14mattmitchellohpauleez: oh cool ok. that's exactly what i'm looking for.
12:14ohpauleezYou would normally just use, B and A in C. I personally prefer require, or use-only so that it's clearly documented what I'm using, and where it came from.
12:14ohpauleezmattmitchell: awesome! Glad I could help
12:14mattmitchellohpauleez: ok so another related question, is it possible to define a function in a different namespace?
12:15ohpauleezmattmitchell: http://clojuredocs.org/clojure_core/clojure.core/in-ns
12:16ohpauleezactually, with-ns is probably what you want
12:16ohpauleez&(doc with-ns)
12:16sexpbotjava.lang.Exception: Unable to resolve var: with-ns in this context
12:16ohpauleezit's in contrib
12:17ohpauleezmattmitchell: http://clojuredocs.org/clojure_contrib/clojure.contrib.with-ns/with-ns
12:17mattmitchellohpauleez: excellent thanks again!
12:17ohpauleeznp, glad I could help!
12:42momosPerhaps a lot of you is developing in Clojure at work or for commercial projects. do you publish your code on github etc? if yes, how do you link the commercial and open-source side? under what license do you publish the code?
12:45ejacksonmomos: a good example of this is Bradford Cross's stuff. Check out https://github.com/getwoven. I guess the license is in there somewhere if you look.
12:45momoshmm I've seen this repo somewhere
12:47ejacksonit used to be called clj-sys
12:48momosthe license isn't very noticeable.... can't find it
12:48momosmaybe there's a default one for clj :P
12:49momosah.ok. there are a bunch of mit licenses just on some projects
12:51ohpauleezmomos: I'm sure you'll see mostly EPL or MIT/BSD licenses for things
12:51ohpauleezyou can then take those, and use them in a private, proprietary project
13:26amalloypdk: if you're looking for logical xor: ##(apply not= (map boolean [:a :b]))
13:26sexpbot⟹ false
13:27pdkGASP
13:44defn'lo
13:47boboif im handed a vector thats realy a map ie [key1 val1 key2 val2] whats the simplest way to turn it into a real map?
13:47bobocant figure something simple out
13:47mefestobobo: vec i think
13:48mefesto,(vec [:a 1 :b 2 :c 3])
13:48clojurebot[:a 1 :b 2 :c 3]
13:48mefestooops, what am i thinking :)
13:48bobo:-)
13:48mattmitchellcould someone show me how i could "dry" this up? https://gist.github.com/797191
13:48mefesto,(apply hash-map [:a 1 :b 2])
13:48clojurebot{:a 1, :b 2}
13:49bobomefesto: ofcource! thanks
13:49mattmitchellthe only differences between the 2 are the names of the database table and a mapping in "m"
13:50chousermattmitchell: (db/partners (documentor m/partner))
13:50chouserthen just write your documentor function
13:54mattmitchellchouser: oh right. so pass in the functions, don't immediately execute them
14:03KirinDaveIt's so cute when someone is like, "Oh dang, macros are pretty weird." for the first time.
14:03KirinDavee.g., http://brandonbyars.com/2008/02/12/understanding-syntactic-macros/ that is making its way around hackernews
14:06mattmitchellhow do i get a reference to a function in another namespace and pass it off as a callback to something else?
14:07ScorchinHey guys, I sent in a pull request a while back to clojure-contrib and it's not been merged. I realise it's probably because it's not considered good enough, but I'd love to know why so I don't make the same mistake again. Pull request here: https://github.com/clojure/clojure-contrib/pull/4
14:08chousermattmitchell: just use its name
14:08hiredmanScorchin: you should read the guid for contributing on the clojure website
14:08chouser, clojure.core/filter
14:08clojurebot#<core$filter clojure.core$filter@1c0035b>
14:08hiredmanScorchin: clojure and clojure-contrib don't take pull requests
14:08Scorchinhiredman: Thanks! That makes a lot of sense
14:09mattmitchellchouser: oh that's embarrassing, thanks :)
14:10nishanthow can I start swank with a bigger heap?
14:20nishantnevermind
14:52pauldoohow do I zip two sequences together? e.g. turn [[1 2 3] [4 5 6]] into [[1 4] [2 5] [3 6]]
14:52chouser,(map vector [[1 2 3] [4 5 6]])
14:52amalloy&(map vector [[1 2 3] [4 5 6]])
14:52clojurebot([[1 2 3]] [[4 5 6]])
14:52sexpbot⟹ ([[1 2 3]] [[4 5 6]])
14:52chouserwow
14:52amalloyhaha
14:52amalloy&(apply map vector [[1 2 3] [4 5 6]])
14:52sexpbot⟹ ([1 4] [2 5] [3 6])
14:53chouserexactly the same mistake at exactly the same moment
14:53amalloyi was even thinking "do i need apply here? no, not for this instance, because map works on a sequence"
14:53chouserpauldoo: hi, btw.
14:54amalloypauldoo: there's also ##(apply zipmap [[1 2 3] [4 5 6]]) if you want it as a map instead of an ordered set of pairs
14:54sexpbot⟹ {3 6, 2 5, 1 4}
14:54pauldooaha! the vector function is useful! :)
14:54pauldoocunning!
14:54pauldoochouser: hello to you to. :)
14:55semperosincanter does something similar
14:57__name__sexpbot: (contains? '(1 2 3) 1)
14:57__name__&(contains? '(1 2 3) 1)
14:57sexpbot⟹ false
14:57fogus`pauldoo: And also ##(apply interleave [[1 2 3] [4 5 6]]) if you don't want them grouped in vectors. ;-)
14:57sexpbot⟹ (1 4 2 5 3 6)
14:57__name__why does it just randomly say false instead of failing?
14:58pauldoofogus`: right-o
14:58pauldooI'm twatting about reimplemting "separate" so that the filter function is only called once per element
14:58chouser__name__: well, it has no keys at all, so I guess it doesn't have a key of 1
14:59pauldoo(defn separate [f s]
14:59pauldoo (let [t (map vector (map f s) s)]
14:59pauldoo [ (map second (filter first t)), (map second (filter (complement first) t)) ]))
14:59pauldoois the best I have so far
14:59amalloy__name__: there is nothing random, and it is not failing
15:00amalloycontains? is for seeing if a map contains a key, not if a list contains a value
15:00amalloyyou want ##(doc some) for that
15:00sexpbot⟹ "([pred coll]); Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll)"
15:00__name__amalloy: why does it work on a list then?
15:01fogus`__name__: This explains it well. http://en.wikibooks.org/wiki/Clojure_Programming/FAQ#Why_doesn.27t_contains.3F_do_what_I_expect_on_vectors_and_lists
15:01amalloy&(some #{1} '(1 2 3))
15:01sexpbot⟹ 1
15:01__name__i know that that is how it is done, but why does the compiler not tell?
15:02amalloy$source contains?
15:02sexpbotcontains? is http://is.gd/60Qkhn
15:02__name__ah
15:02__name__i see
15:02__name__now it makes sense, thanks
15:02amalloywelcome
15:03shortlordis there some operator like for that travesers multiple bindings parallel? like (for [x [1 2 3 4] y [1 2 3 4]] [x y]) => [[1 1] [2 2] [3 3] [4 4]]
15:03chousershortlord: map
15:04chouser,(map vector [1 2 3 4] [1 2 3 4])
15:04clojurebot([1 1] [2 2] [3 3] [4 4])
15:04chouseramalloy: where were you?
15:04shortlordchouser: not as easliy understandable with big expressions as functions, but I guess it has to do
15:05amalloychouser: jeez sorry, i guess i have to quit my job to keep up with you
15:05amalloyshortlord: you can do this with for also
15:05chousershortlord: I've thought about how to add that as a feature of 'for' somehow, but I haven't come up with anything that isn't clearly worse.
15:05amalloyor...no, maybe you can't
15:05chouseramalloy: well, it was the same answer as we tied on last time. I assumed I was racing you again. ;-)
15:06shortlordchouser: well, there are already tags like ':let', right? something like ':parallel' would be nice
15:06amalloy&(for [[x y] (interleave [1 2 3 4] [:a :b :c :d])] [x y])
15:06sexpbotjava.lang.UnsupportedOperationException: nth not supported on this type: Integer
15:07chousershortlord: but how would you use it that doesn't end up looking like just a 'map' inside the 'for'?
15:07nickikfirst we should get the pmap stuff write (fj) then we can start build parallel everything on top of that.
15:07chouserdifferent kind of parallel
15:08amalloychouser: but wouldn't it be so much fun to combine them
15:08shortlordchouser: what do you mean? you could just use something like [x y] inside the for, which should be quite nice in cases where you have large expressions that otherwise would have to be defined as functions previously
15:09chousershortlord: do you have an example in mind of how you could use it?
15:12shortlordchouser: I have an application where I have a vector that holds a lot of similar maps (it's a field made up of fields with quite a few attributes). Now I am using a token that marks one field; this token is a ref that stores the vector index of the field that it references
15:12amalloyshortlord: i think he means, write a for statement using the syntax you wish existed
15:12chousershortlord: I guess I'm talking about about the syntax than the semantics. Do you have a little code snippet of how you'd use for with :parallel?
15:13chouser:-)
15:15shortlordchouser: I'm not sure whether I understand what you want. The syntax should be as simple as that: https://gist.github.com/797350 If you want a usecase, that's what I've tried to describe
15:16chousershortlord: so :parallel would group the previous binding (x in your example) with the following (y)
15:17chouserif you had more than two in the group, you would pu :parallel between all of them (like infix notation)?
15:17chouser:when and :while would be illegal inside such groups?
15:19tonylthat is a very big macro
15:19tonylfor
15:19chouseryes. yes it is.
15:20shortlordchouser: ':parallel' would be used equal to :let, so :while and :when should still be allowed. :parallel would just make the bindings after it run at the same index as the main binding in for. But yes, having several bindings in the main for block zould be a problem
15:21amalloyshortlord: there is no "main" binding
15:21shortlordamalloy: I mean the normal binding pair without any tags
15:22mefestothis is to avoid (map vector xs ys zs) ?
15:23shortlordmefesto: in case the function is a simple as vector, map is clearly a good choice. but for with such a tag could be nice for larger expressions
15:23chouserright. (for [[x y] (map vector [1 2 3 4 5] [1 2 3 4 5])] [x y]) would be one way to write that gist currently
15:23mefesto(for [[x y z] (map vector xs ys zs)] [z y x])
15:25chouserMaybe (for [[x y z] :parallel [xs ys zs]] ...) :-)
15:32tonylif there are lager expressions, just pull them up as a function
15:37shortlordtonyl: yeah, I guess that should do the job well enough
15:38shortlordwhat is the recommended way to create a map for a small collection of things? array-map?
15:38amalloychouser: not sure if you were serious with your last suggestion but that would mess up the binding-partitioning
15:39tonylhash-map
15:39tonyl&(hash-map 1 2 3 4)
15:39sexpbot⟹ {1 2, 3 4}
15:39__name__why can i not add metadata to an integer?
15:39amalloyshortlord: probably (into {}), which will decide for you whether to use an array
15:39amalloy&(instance? IObj 1)
15:39sexpbotjava.lang.Exception: Unable to resolve symbol: IObj in this context
15:40amalloy&(instance? clojure.lang.IObj 1)
15:40sexpbot⟹ false
15:40__name__or, rather, how can i attach it?
15:41chouseramalloy: yeah, I wasn't very serious
15:43amalloy__name__: put it on something other than an integer :P
15:44__name__amalloy: I guessed that.
15:44amalloy&(-> 10 vector (with-meta {:name "frank"}) ((juxt first meta)))
15:44sexpbot⟹ [10 {:name "frank"}]
15:46shortlordhow random is clojure's shuffle? it does not seem to shuffle a seq a lot
15:47amalloyshortlord: as random as pseudorandom gets. it calls java.util.Collections.shuffle
15:48amalloy$source shuffle
15:48sexpbotshuffle is http://is.gd/xc6JDT
15:48shortlordamalloy: ok. I guess it just seems not very random at times... normal paranoia ;)
15:49amalloyindeed. humans are terrible at randomness
15:50hiredmanI suggest running some stats
15:53__name__$source with-meta
15:53sexpbotwith-meta is http://is.gd/D0GjxE
15:58__name__&(with-meta 1/1 {:k "v"})
15:58sexpbotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IObj
15:58__name__&(with-meta 1/2 {:k "v"})
15:58sexpbotjava.lang.ClassCastException: clojure.lang.Ratio cannot be cast to clojure.lang.IObj
16:04robonobo__name__, you can private message sexpbot if you want to use it's services without flooding the channel
16:04pdk(doc repeatedly)
16:04clojurebot"([f] [n f]); Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls to it"
16:04__name__i did not flood the channel, did i?
16:04pdk(doc repeat)
16:04clojurebot"([x] [n x]); Returns a lazy (infinite!, or length n if supplied) sequence of xs."
16:04robonobo__name__: no, but you were of risk of doing
16:05__name__robonobo: why?
16:05robonobojust use sexpbot here if it's pqrtof dicussion
16:06__name__robonobo: it was, kind of.
16:06robonobooh, i see, cqrry on, my apologies good sir
16:07brehautrobonobo: you need to get your \a key checked
16:07semperosperhaps he's using a French keyboard
16:08thunerHe everyone!
16:08thunerI followed the instuction if https://github.com/richhickey/clojure-contrib/blob/master/README.txt, however the command "mvn package" did not created the target directory. Anyone had the same issue?
16:09amalloythuner: richhickey's repository is quite out-of-date. i don't know if it will fix your specific problem but you should use the clojure/clojure-contrib repo
16:10thunerthank's I'll give a look at it
16:19__name__amalloy: is there no way to wrap an integer in something that implements IObj if one wants metadata?
16:19amalloy__name__: what's wrong with the vector-wrapping snippet i gave?
16:20__name__amalloy: that it returns [int meta] instead of the int with the meta attached?
16:21tonyl__name__: you could reify your own "box" I don't know how that would affect your algorithm
16:21amalloy&(-> 10 vector (with-meta {:name "frank"}))
16:21sexpbot⟹ [10]
16:21amalloythe ((juxt first meta)) at the end is to unwrap that into the original integer and the meta you attached to the vector
16:22chouseryou'd have to decide what operations on the number retain which metadata
16:22amalloynot that this is really a great idea anyway. instead of attaching meta to an integer, why not just use a real datastructure that stores the information you need
16:27semperoslearning ring-based web application in Clojure, using enlive and moustache
16:27semperosI define an enlive template (deftemplate) called "index"
16:27semperosdeftemplate returns a lazy seq of strings
16:28semperosI then use ring.util.response/response to put that into the :body of a response
16:28semperos(response (index))
16:28__name__amalloy: it's more of a principle thing really.
16:28__name__amalloy: I just wished i could attach metadata without caring what type the data is.
16:28semperoson the repl, the lazy seq is evaluated, and I see what I expect
16:29semperosbut when I run it in my web app, I just get a string representation of the lazy seq, "clojure.lang.LazySeq@dd5c324b"
16:29brehautsemperos: i use (defn render [s] (apply str s)) from dnolen's enlive tutorial
16:29semperosyeah
16:29semperosI nkow I can do apply str all over the place :)
16:29semperosbut the Ring spec says it takes an ISeq
16:29semperosof strings
16:29semperosin addition to a plain string
16:29semperoswas wondering if I was missing something obvious
16:30semperosabout the evaluation of a deftemplate's lazy seq of strings
16:34brehautsemperos: ring.uril.servlet/set-body does check for seq's
16:34brehautsemperos: https://github.com/mmcgrana/ring/blob/master/ring-servlet/src/ring/util/servlet.clj#L79-83
16:35semperosright
16:35semperosit works at the repl, when I give the :body a seq of strings
16:36semperosjust not in the app
16:36brehautdoes (seq? (index ...)) return trye?
16:36semperosyes
16:37semperosin the app, the :body is actually set to "clojure.lang.LazySeq@xxxxx"
16:38brehautwhich is what you would expect if str is called on the lazy-seq directly
16:38brehaut(str (lazy-seq [1 2]))
16:38brehautbah
16:38brehaut$(str (lazy-seq [1 2]))
16:38chouseruse & or ,
16:38semperos&(str (lazy-seq [1 2]))
16:38sexpbot⟹ "clojure.lang.LazySeq@3e2"
16:38brehautthanks
16:39semperosyep, I get that
16:39semperosI'm sure I'm just missing something very basic
16:40semperosso (response) takes anything that is allowed by the Ring spec as part of the response :body
16:40semperosand sticks it in there
16:40semperosso at the repl, if I do (response (index)), I get everything evaluated correctly
16:40semperosdoesn't do the same when I add it to a route with moustache
16:40semperos[""] {:get (fn [req] (response (index)))}
16:41semperosthat's my confusion
16:45LauJensenFor the Emacsers in here: http://offtopic.bestinclass.dk/post/2942525776/my-emacs-color-theme
16:46semperosnice
16:49robonoboLauJensen: your server seems to be down
16:49LauJensenrobonobo: ?
16:49LauJensenrobonobo: http://www.downforeveryoneorjustme.com/
16:50neilcjnot down for me ;)
16:50__name__neither
16:51neilcjLauJensen: pretty theme, thanks for sharing
16:51robonoboit's back after a few tries (it was a maximum bandwith exceededthing, but with nicer layout)
16:52pdkdid i ever mention
16:52pdkthe parens matching in vimclojure has a really bad case of alzheimer's
16:53brehautsemperos: what middleware are you using (if any)
16:53semperosstacktrace, keyword-params, reload, and a custom one; going to try without the custom one
16:54semperosgah
16:55semperoswell, that pinpoints where the error was
16:55brehaut:)
16:55semperosnot surprisingly, my own mess
16:55LauJensenneilcj: np :)
16:56LauJensenpdk: Thats fair enough, since you yourself have got to have a pretty bad case of alzheimers to be using Vim in the first place
16:56brehautLauJensen: theme looks nice
16:56LauJensenbrehaut: thanks - notice how the foreground != the background. You could learn a few things :)
16:56brehautLauJensen: could do with some more eye searing yellow though
16:56LauJensenbrehaut: its got plenty yellow - I even got a complaint on twitter about it
16:56brehauthaha
16:56brehautclassic
16:56pdkwellllll
16:56pdkgranted!
16:59ohpauleezI use wombat, and still love it: http://dengmao.wordpress.com/2007/01/22/vim-color-scheme-wombat/
17:00ohpauleezI made a 256 color scheme for it
17:02LauJensenohpauleez: You can paint Vim... but its still Vim :(
17:03ohpauleezhaha you're relentless LauJensen
17:03LauJensenIndeed :)
17:03LauJensenIts called Persistent
17:03ohpauleezparedit.vim + vimclojure + vim + zsh seems to do the trick for me
17:04LauJensenoh, you didn't tell me you were a beginner.. Beginners are allowed to evaluate their tools
17:05wolverianthere's a paredit.vim? oh my.
17:05wolverianoh, slimv.
17:06wolverianI never managed to get vimclojure and slimv working together. slimv would force lisp syntax highlighting on my buffers.
17:06chouserexperts must accept LauJensen's word without question
17:06LauJensenYou can trust chouser, he's been here forever
17:10ohpauleezwolverian: I just yanked paredit.vim out of slimv
17:10ohpauleezhaha LauJensen I just caught myself up
17:11LauJensenohpauleez: So you're using Emacs now?
17:11ohpauleezI always *HAVE* used it. Clojure is the first Lisp I feel comfortable editing in vim, and do most of my day to day edits in vim. But yes, I use both
17:11ohpauleezthere, I admitted it :)
17:12brehautohpauleez: clojure is the first lisp i have felt comfortable editign in emacs
17:12LauJensen:D
17:13LauJensenI gotta take off gents, but as always, it was fun hanging out with you :)
17:13brehautgnite lau
17:13ohpauleezlater
18:04__name__http://paste.pocoo.org/show/327503/
18:05__name__how do i prevent this from happening?
18:07brehaut__name__: which clojure are you using?
18:07brehaut__name__: 1.3?
18:07__name__brehaut: 1.2
18:07__name__oh, wait
18:07__name__it's 1.3
18:08brehaut*clojure-version*
18:08brehautthats why
18:08__name__yes, i typed it into the wrong repr. i am deeply sorry.
18:08brehautno problem
18:09__name__oh, and of course `map second`
18:10__name__note to self: do not code in an unfamiliar language when not well-rested, and if you do, do not annoy nice irc people.
18:12amalloy__name__: transitioning from common-lisp, it looks like? or maybe scheme?
18:12__name__amalloy: python, actually :-)
18:12brehautthat would explain your handle :)
18:13__name__amalloy: what made you think i am a schemer or clisper?
18:13amalloy__name__: interesting. i know python has [a b c] list literals, so i'm a bit puzzled as to why you're not using clojure's
18:13amalloy(list blah blah) and '(blah blah) are easily replaced by [blah blah]
18:13__name__amalloy: because they are vectors?
18:13__name__amalloy: if i am not completely mistaken it's not the same thing
18:14amalloy__name__: vectors are almost always better for handling data
18:14__name__But in this case a vector is better.
18:14amalloyi mean, it doesn't matter for tiny-little lists
18:14__name__because i am not doing any stuff that you would use linked lists for.
18:14amalloybut the syntax is more convenient for vectors, and it rarely matters which you use if you're not adding
18:14__name__Yes, that's what I meant.
18:15amalloy__name__: plus, vectors support fast adding to the end, while lists support fast adding to the front
18:15amalloyso even if you're using it as a linked list you have to choose
18:15amalloychouser: now's your chance! sell us all on finger trees!
18:16__name__amalloy: http://paste.pocoo.org/show/327511/ is this better?
18:16amalloyyep
18:17__name__i'm amazed i've come up with this :)
18:17amalloydepending on how comfortable you are with destructuring, you can make it still-more readable
18:17amalloy&(fn fib [[a b]] [(+ a b) b])
18:17sexpbot⟹ #<sandbox11874$eval14090$fib__14091 sandbox11874$eval14090$fib__14091@b94d90>
18:18__name__amalloy: Thank you.
18:18__name__amalloy: I just meant to try that myself :)
18:19__name__i guess defn fibs [] (map second (iterate (fn [[x y]] [(+ x y) x]) [1 1]))) is too much of the good
18:19amalloy__name__: http://rosettacode.org/wiki/Fibonacci_sequence#Clojure
18:19amalloyis in fact what you've just done
18:20__name__Yep
18:20amalloy(i added the commented version a few months ago)
18:20brehaut,(let [f (lazy-cat [1 1] (map + ff (rest ff)))] (take 5 ff))
18:20clojurebotjava.lang.Exception: Unable to resolve symbol: ff in this context
18:20brehauti am a muppet
18:21brehaut,(let [f (lazy-cat [1 1] (map + f (rest f)))] (take 5 f))
18:21clojurebotjava.lang.Exception: Unable to resolve symbol: f in this context
18:21amalloyanyway nice work __name__. it's impressive to come up with the strategy of using iterate to store temporary data
18:21brehautunequivocally so apparently
18:21__name__amalloy: i started with recursion, and saw that it's no use for tail calls …
18:22arohneraccording to visualvm, it appears my app is spending a significant chunk of time in PersistentHashMap$HashCollisionNode.findIndex(). Are there any clever strategies for reducing the number of hash collisions in my data?
18:22arohner(I assume that hitting a different node type in PHashMap will improve my performance)
18:23brehaut__name__ the nerdy name for the solution you came up with is a hylomorphism
18:24brehaut(roughly)
18:25brehautie, converting a recursive algorithm into a stream generator and a stream consumer
18:26__name__brehaut: thank you for your elaboration. i appreciate it.
18:28brehaut__name__ no problem
18:31brehaut__name__: also, (nth n ...) is (first (drop n...))
18:32brehautalthough i think i have the args backwards
18:32__name__I ended up with (defn fibs [] (map second (iterate (fn [[x y]] [(+ x y) x]) [1 0]))) by now
18:32__name__i had forgotten the 0
18:32__name__Am I right in believing that at any point in time there's only x and y in memory?
18:33brehautyup
18:33__name__yay
18:34__name__thanks for putting up with my ignorance :)
18:35brehautnah, ignorance is when you type stupid crap into clojure bot rather than a repl
18:35brehautand then make the same mistake again
18:35brehaut__name__ how familiar are you with generators, generator expressions and itertools in python?
18:35__name__brehaut: very
18:36amalloyer, no. only x and y are *required* to be in memory. the gc won't clean them up till it needs to
18:36__name__amalloy: Oh; Sorry for being vague, I meant that.
18:37amalloy__name__: preface: i don't think the following is actually better than your version
18:38amalloyoh actually i take it back, this version is awesome
18:38amalloyyou could implement (fn [[x y]] [(+ x y) x]) as (juxt (partial apply +) first))
18:39__name__amalloy: would you mind explaining, i looked at the doc of juxt (and know what partial does), but do not seem to grasp it.
18:40brehaut,((juxt inc dec) 1)
18:40clojurebot[2 0]
18:40amalloywell, ideally it would be just (juxt + first), which makes more sense
18:41amalloybut because [x y] is a list, you need to ##(apply + [1 2])
18:41sexpbot⟹ 3
18:41__name__amalloy: are you a haskeller?
18:41amalloy(partial apply +) wraps that up in a new function that will add the list it's passed
18:41amalloy__name__: no, but i keep hearing i should be
18:41amalloyi think point-free is nice
18:41brehautthe haskell solution ported to clojure is
18:42brehaut(def fibs (lazy-cat [1 1] (map + fibs (rest fibs))))
18:43brehautturns out i was right previously but i (obviously) need a var in the road, to make it self recursive
18:43amalloy&with-local-vars
18:43sexpbotjava.lang.Exception: Can't take value of a macro: #'clojure.core/with-local-vars
18:43__name__amalloy: I understand
18:44brehaut,(with-local-vars [fib (lazy-cat [1 1] (map + fibs (rest fibs)))] (take 10 fibs))
18:44clojurebotjava.lang.Exception: Unable to resolve symbol: fibs in this context
18:45amalloybrehaut: the var doesn't exist until its init expr is done
18:46brehautalso i typod
18:46amalloy&(with-local-vars [fibs nil] (var-set fibs (lazy-cat [1 1] (map + (var-get) fibs (rest (var-get fibs))))) (take 10 (var-get fibs)))
18:46sexpbotjava.lang.IllegalArgumentException: Wrong number of args (0) passed to: core$var-get
18:46amalloyblah whatever
18:47amalloy&(with-local-vars [fibs nil] (var-set fibs (lazy-cat [1 1] (map + (var-get fibs) (rest (var-get fibs))))) (take 10 (var-get fibs)))
18:47sexpbotjava.lang.IllegalStateException: Var null/null is unbound.
18:47brehautamalloy: im glad its not just me :/
18:47arohnermore info on my hash collision problem. I have a map w/ 33k keys, but 6.7k distinct hash codes (according to (->> my-map keys (map #(.hashCode %)) distinct count
18:47amalloy&(with-local-vars [fibs nil] (var-set fibs (lazy-cat [1 1] (map + (var-get fibs) (rest (var-get fibs))))) (doall (take 10 (var-get fibs))))
18:47sexpbot⟹ (1 1 2 3 5 8 13 21 34 55)
18:47__name__yay
18:47amalloybrehaut: solved!
18:48amalloyvile though it is
18:48brehaut(inc amalloy )
18:48sexpbot⟹ 2
18:48brehautwoo :-)
18:48brehautyeah remarkably so
18:48brehautthe basic concept is so tidy too
18:49Leonidas__name__: I'm not haskeller either and partial and thread-last are seriously nice ;)
18:49amalloypartial is...really handy, and way too verbose
18:49__name__Leonidas: oh hey
18:49brehautamalloy: thats why we have % ;)
18:49brehauterr #
18:50Leonidas__name__: hi :)
18:50Leonidas__name__: I'm currently in clojure-hack mode :D
18:50amalloyone day i'll cross over to the dark side and (def ##(char (rand-int 0xffff)) partial)
18:50sexpbot⟹ \練
18:50__name__Leonidas: i'm in ‘i should go to sleep’ mode.
18:51brehautamalloy: i apparently dont have that glyph
18:51amalloybrehaut: i don't either, it's too high in the code charts
18:51Leonidas__name__: same here. and "i should learn for exams" mode. this is the one time in the semester when I start to hack productively :)
18:51__name__Leonidas: :)
18:51amalloy&(char (rand-int 0x8fff))
18:51sexpbot⟹ \佗
18:51brehauthah awesome
18:52amalloyalthough FAB0 is the best random character ever
18:52amalloyit's FAB0LOUS!
18:52__name__&(char 0xdead)
18:52sexpbot⟹ \?
18:53Leonidas,(char 0xFAB0)
18:53clojurebot\練
18:53amalloythat's how haskellers roll, isn't it? define single-unicode-character names for the useful functions?
18:53Leonidaswhich of these bots is actually to prefer?
18:54brehautnah, its more like a like a crazy pipe of 2 to 5 punctiation characters as a binary op
18:54amalloyLeonidas: sexpbot imo, but i'm biased as i've been helping write/maintain him for months now
18:55Leonidasamalloy: :)
18:55brehautamalloy: your homework is to explain the difference between (.) (>>>) and (>=>)
18:57brehautvalid answers do include 'not much'
18:58arohner&(.hashCode {62 0, 75 1720, 73 1})
18:58sexpbot⟹ 1913
18:58arohner&(.hashCode {75 1717, 62 1, 61 1})
18:58sexpbot⟹ 1913
18:59amalloyarohner: (hash x) is the same as (.hashCode x)
18:59arohneramalloy: thanks, but not my issue ATM
18:59amalloy*laugh* i know
18:59arohner&(hash {75 1099})
18:59sexpbot⟹ 1024
19:00arohner&(hash { 69 24 61 1 75 812})
19:00sexpbot⟹ 1024
19:00arohnerI can do that 28k more times
19:00arohnerout of 33k maps
19:01amalloyhave you looked at the source of map.hash?
19:02arohneryeah. it doesn't look very random (though I could have told you that empirically )
19:02amalloyit looks like it's pretty bad, yeah
19:03amalloyarohner: you could probably make it sufficiently good just by adding hash *= 13 before the +=
19:05amalloyperhaps that just slows things down too much for rich
19:08arohneramalloy: if you think computing hashes is expensive, you should try dealing with hash-collisions :-)
19:08arohneramalloy: I'll try out a build with *= 13, and we'll see what happens
19:08amalloyarohner: that's only an issue if maps containing elements with weak hash functions are stored inside of another mapo
19:09amalloyso i doubt it comes up much in practice
19:09arohner&(hash 1238907)
19:09sexpbot⟹ 1238907
19:10arohnermy data is not distributed randomly. The keys are db ids, and the values are ids of enums that users have selected
19:11amalloyarohner: yes, i understand why it comes up for you
19:12amalloymy point is that it may not come up often enough in general to merit slowing down map hashing; the hit there might be worse than the occasional reduction in collisions
19:16__name__thanks, especially amalloy and brehaut; good luck with the exam, Leonidas. good night all.
19:17Leonidas__name__: goodnight.
19:22symuynIs a vector's hash code calculated when the vector is created, or is it lazily calculated when hash or = is called?
19:24amalloysymuyn: on hash
19:24symuynWhen hash is called?
19:24amalloyyes
19:24symuynGood, that makes sense
19:24symuynBy the way, does vector's isEquals use hash codes?
19:24symuynisEqual, I mean
19:25amalloysymuyn: bizarrely enough, the answer is "sometimes"
19:25symuynHmm
19:26amalloyfor List and PersistentVector, it checks their hash codes
19:26amalloyfor Sequential objects it goes straight to comparing
19:26symuynAren't List and PersistentVector inside Sequential?
19:26symuynOh wait, they can override
19:27symuynBut what doesn't override Sequential.isEqual?
19:27amalloy&(some #{clojure.lang.Sequential} (supers (class [])))
19:27sexpbot⟹ clojure.lang.Sequential
19:27symuynYeah
19:27symuynOh well. Clojure does a good job of hiding this stuff anyway
19:28amalloysymuyn: the persistent data structures have a doEquiv and doEquals
19:28symuynI forgot: are all Sequential objects persistent?
19:28amalloyequiv is what's called by (= foo bar), and it never checks hash codes b/c it needs [1 2] to equal (1 2)
19:29symuynI thought that [1 2] and (1 2) had equal hash codes; I was told that yesterday
19:29symuyn@(= (hash [1 2]) (hash '(1 2)))
19:29amalloythey probably do, but that's not really a guarantee
19:30symuynUgh
19:30symuyn&(= (hash [1 2]) (hash '(1 2)))
19:30sexpbot⟹ true
19:30amalloy&(map hash ["" 1] #{"" 1})
19:30sexpbotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$hash
19:30mefestoanyone use clojure-rabbitmq in here?
19:30amalloy&(map hash [["" 1] #{"" 1}])
19:30sexpbot⟹ (962 1)
19:31amalloy&(apply = [["" 1] #{"" 1}])
19:31sexpbot⟹ false
19:31amalloywell, that's good at least
19:31amalloy&(apply = [[1 ""] #{"" 1}])
19:31sexpbot⟹ false
19:31amalloyanyway i think it's a complicated issue
19:31symuynWait, really?
19:31symuyn&(= #{} [])
19:31sexpbot⟹ false
19:31symuynHuh. Sets and vectors aren't equal.
19:32symuynThat might bite me someday
19:32symuynI wonder what the rationale is
19:32brehautsymuyn: that makes sense though right? vectors have additional information encoded in them than sets
19:32symuynAh, right.
19:33symuynI need to think of collection equality as sequence equality
19:33symuynWait, that might not work for sets to sets
19:33brehaut,[(hash (lazy-seq [1 2 3])), (hash (lazy-seq [3 2 1]))]
19:33clojurebot[30817 32737]
19:34brehauti dont know why i made those lazy
19:34amalloybrehaut: an extra sprinkling of awesome
19:34brehautamalloy: i like how you think
19:36brehautsymuyn: i think realistically you need to have much crisper notions of equality
19:38symuynbrehaut: I think that sequentials vs. non-sequentials are fine. "All sequentials are equal if blah, blah, but are never equal to non-sequentials. Non-sequentials are equal if they contain the same elements, but are never equal to sequentials."
19:38brehautsymuyn: what about a sorted set compared to a vector?
19:38symuyn&(= (sorted-set 1 2 3) [1 2 3])
19:38sexpbot⟹ false
19:39symuynYeah, okay
19:39brehautyeah, and even worse
19:39symuynWell, so much for consistency
19:39brehautis (sorted-set 1 2 3) different to [1 2 2 3]?
19:40symuyn&(= (sorted-set 1 2 3) [1 2 2 3])
19:40sexpbot⟹ false
19:41brehautreally, you need to convert one side of your test into the other type
19:41brehaut,(= (sorted-set 1 2 3) (apply sorted-set [1 2 2 3]))
19:41clojurebottrue
19:42symuynUgh, apply is so slow; it's been the bottleneck of my programs in the past
19:42brehaut,(= (vec (sorted-set 1 2 3)) [1 2 2 3])
19:42clojurebotfalse
19:42symuynThank goodness for vec
19:43symuynDo you know if there's a way to turn off pre/post-conditions, like tests?
19:43brehautsymuyn: the point being though, depending on how you are viewing _the same data_ equivalence can change dramatically
19:43symuynYeah
19:43brehaut(same excluding collection information)
19:43amalloy&(time (apply + (range 1e5)))
19:43sexpbot⟹ "Elapsed time: 26.930893 msecs" 4999950000
19:44amalloysymuyn: apply really isn't slow, i don't see what problem you're experiencing
19:44amalloy&(time (reduce + (range 1e5)))
19:44sexpbot⟹ "Elapsed time: 30.868435 msecs" 4999950000
19:44brehautamalloy: i imagine applying a collection constructor to a large collection is going to be a slow operation ;)
19:44symuynamalloy: It happened twice a year ago. Perhaps I'm wrong, but I'm pretty confident
19:45amalloybrehaut: sure, but not any slower than (doall (map identity coll))
19:45brehautamalloy: oh for sure, its not the result of apply that its slow
19:47amalloysymuyn: you found that (foo x y z) was substantially faster than (apply foo [x y z])? i guess i could see that, if foo had a lot of different arities defined
19:47symuynWhy would the number of arities matter?
19:49brehautsymuyn: a function call can choose the implementation at compile time, an apply call has to determine the implementation at runtime
19:50symuynYes, but does the search time depend on the number of arities? Maybe it's constant to the number. But the again, I've no idea.
19:52brehautsymuyn: i cant intuit how it could be constant time
19:53brehaut$source apply
19:53sexpbotapply is http://is.gd/AklWob
19:53brehauti must confess to that not clearing things up for me
19:54symuynThe source there doesn't show the implementation of arity selection.
19:54symuynIt doesn't really matter that much anyway
19:54symuynI'd think that we'd have to look in clojure.lang.IFn (or .Fn?) but I don't like looking in Clojure's guts
19:55brehauthttps://github.com/clojure/clojure/blob/1.2.x/src/jvm/clojure/lang/AFn.java#L154
19:55symuynAh, now that's interesting
19:55hiredman,((fn [& x] (first x)) (iterate inc 0))
19:55clojurebot(0 1 2 3 4 5 6 7 8 9 ...)
19:55hiredmanerm
19:55hiredman,(apply (fn [& x] (first x)) (iterate inc 0))
19:55clojurebot0
19:55symuynNow, doesn't collection counting have near-constant-time?
19:55hiredmanapply doesn't count
19:56symuynWait, no
19:56hiredman^- apply to an infinite seq
19:56brehautapply does magic
19:56symuynThe arglist is an ISeq
19:56symuynSequence counting is linear
19:57symuynhiredman: That's interesting
19:57brehauthttps://github.com/clojure/clojure/blob/1.2.x/src/jvm/clojure/lang/RT.java#L1184
19:57symuynThat kind of boggles my mind, actually
19:57symuynYes, and there we have it
20:01brehautalso im presuming that Util.ret1 at https://github.com/clojure/clojure/blob/1.2.x/src/jvm/clojure/lang/AFn.java#L151 is used to let java release the seq?
20:03hiredmanyes, java doesn't have a way of clearing the jvms method frame while keeping a reference on the method's stack
20:03brehauthiredman: cheers
20:22brehautsymuyn: relevant to the discussion http://groups.google.com/group/clojure-dev/browse_thread/thread/c58ec42d78209ee0
20:24symuynbrehaut: Thanks; that's very interesting
20:24symuynOops, wrong punctuation
20:26brehautsymuyn: and by experimention i gather than sorted-sets test equality as sets by default, and seqs if you wrap them seq; YMMV of course, ididnt read the code
20:26symuynI think you're right in that I should just convert to the same type before comparing
23:09pdk(doc doseq)
23:09clojurebot"([seq-exprs & body]); Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil."
23:09pdk(doc while)
23:09clojurebot"([test & body]); Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become false/nil. Returns nil"
23:16amalloythat's a weird docstring for while
23:16brehautis it weird that i didnt even know there was a while?
23:16amalloy"Presumes some side-effect will cause test to become false/nil" suggests that it is an error to write (while true (...)), because you are violating while's assumption/precondition
23:17amalloybrehaut: yeah, i've never used it either
23:17pdkit's an infinite loop at any rate
23:17amalloypdk: clearly. but there's nothing wrong with writing an infinite loop if that's what you want
23:18technomancybe honest, who reads the docstring for while?
23:18amalloytechnomancy: pdk, it seems
23:18amalloyand now me, to my chagrin
23:19brehautis there an sexp-grep for clojure?
23:20brehaut(ie, for grepping clojure source)
23:20amalloybrehaut: how would that be different from plain old grep?
23:21brehautamalloy: knows about trees rather than lines
23:21brehautgrep is probably the wrong term
23:21brehautxpath is a better one
23:21brehautsexpath
23:21brehautprobably didnt need to go there
23:21amalloylike...sgrep (if (magic))? it's not clear to me how i'd specify useful sexps for this
23:22technomancysounds like you want a zipper
23:22brehautyeah i probably do