#clojure logs

2014-04-17

00:11kennethhey all
00:12kennethso i'm not sure if this is a clojure thing; because i'm actually trying to code in wisp; but
00:12kennethi'm trying to make a macro that creates code which includes a hashmap
00:14ambrosebskenneth: looks like wisp macros are similar to clojure
00:14kennethlet's pretend for the sake of simplicity that i want to (defmacro hello [x] (quote {(keyword x) x})), and i want this (hello foo) to be equivalent to {:foo foo}
00:15kennethwhen i try to include {} in my macro it errors
00:16kenneththis is the code i'm playing with right now: https://gist.github.com/kballenegger/10952318
00:19kennethwisp doesn't seem to have (hash-map :one 2)
00:21ambrosebskenneth: maybe (defmacro [x] `{~(keyword x) '~x})
00:22ambrosebswhat's expected input/output?
00:28dissipatemacros are hard, just use functions
00:30nightflyfunctions are hard, just use expressions
00:35dissipatenightfly, core.logic? :D
00:54FrozenlockI'd like to have a blog with my compojure site. Is there anything plug'n'play for that?
01:03kennethGOT IT
01:03kennethhttps://gist.github.com/kballenegger/10952318
01:03kennethwoooo
01:14sm0kehello i am trying to use piggieback for brepl, is it automatically launched with `lein repl`?
01:28FrozenlockMight be a better idea to just use a subdomain and octopress...
01:37john_swith vim-fireplace, if i'm connected to an nREPL, everything should be evaluated in a single context, right? i have a user.clj and it's working fine from the repl itself but seems to be unavailable from fireplace unless i explicitly require the namespace
01:48irctci am getting the problem with propertis file how to use the seprate data base for testing
01:49ambrosebsjohn_s: do you get an error?
01:49ambrosebsjohn_s: sometimes I need to :reload a namespace via lein to be able to use it in fireplace.
01:49ambrosebsjohn_s: not sure why.
01:50john_sah, interesting. yeah, i get "java.lang.RuntimeException: Unable to resolve symbol: reset in this context"
01:50john_sunless the current buffer is my user.clj or my project.clj
01:55sm0kehmm how do i get sourcemaps working with a ring server?
02:01john_sambrosebs: ah, it appears that (require '[some-ns :refer :all]) wasn't behaving like i expected it to
02:02john_sambrosebs: when switching buffers, i lose the :refer :all (probably a logical way to prevent collisions)
02:02john_sambrosebs: thanks for your help!
02:03ambrosebsjohn_s: ahk cheers
02:32yedibbloom: would love a 'how this differs from CinC" section in the readme for https://github.com/brandonbloom/eclj
02:52irctchello some body plz tell me how we write the config file for my data base
03:50perseshello
03:50kennethwhat if i'd like to concatenate a symbol from two symbols in a macro
03:50derek_ccan you use lein itself to connect to a nrepl?
03:50kennethis that possible?
03:54persesi have a function which return structure like this (([1 2] [3 4]) ([5 5] [0 8])), when apply (apply concat result) i got ((1 2 3 4) (5 5 0 8)), but when try it at repl it's working
03:54perses,(apply concat '(([1 2] [3 4]) ([5 5] [0 8])))
03:54clojurebot([1 2] [3 4] [5 5] [0 8])
03:54persesthat's the right result, but when i do in the code i got it wrong
03:57persesthat's the actual code http://sprunge.us/ICcW
03:58persesi guess the reason is in lasy-seq?
03:58perseseven i print final-edges i got another values
03:58persesmaybe the last values of the last line
03:59perseshow can i got the result for all lines?
04:03persesisn't there anybody here for help?
04:05katratxoderek_c: `lein repl :connect [dest]` https://dpaste.de/5wyv/raw
04:07samratperses: the (def ..) is redefining final-edges each time
04:08persessamrat: so how can i fix this?
04:09derek_ckatratxo: thanks a lot!
04:50perseswhen i save the serialize data to a file and then load this data again as str then deserialize it i got error, i'm using methods there http://sprunge.us/fQca ?
04:50persescan anybody help?
04:51Anderkentperses: what kind of error do you get? Is the byte array large enough?
04:52persesAnderkent: nope i got something string like 1221rer211 only
04:52clgvperses: you probably need to "flush" the stream
04:52clgvbefore you get the array
04:52Anderkentclgv: the OOS is closed before .toByteArray
04:52Anderkentthat should work
04:53clgvah right
04:54Anderkentperses: I assume the missing doublequotes around docstrings are just a paste error
04:54clgvperses: whats your exact input?
04:54clgva quick test worker for me
04:55clgvAnderkent: yeah that too ;)
04:55clgvs/worker/works
04:56clgv,(defn serialize Serializes value, returns a byte array [v] (let [buff (java.io.ByteArrayOutputStream. 1024)] (with-open [dos (java.io.ObjectOutputStream. buff)] (.writeObject dos v)) (.toByteArray buff)))
04:56clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: Parameter declaration Serializes should be a vector>
04:56clgv,(defn serialize [v] (let [buff (java.io.ByteArrayOutputStream. 1024)] (with-open [dos (java.io.ObjectOutputStream. buff)] (.writeObject dos v)) (.toByteArray buff)))
04:56clojurebot#<CompilerException java.lang.ExceptionInInitializerError, compiling:(NO_SOURCE_PATH:0:0)>
04:56Anderkenthuh
04:57clgvah well I got the following (-> {:a "bla"} serialize deserialize) ; => {:a "bla"}
04:57perses[B@bba4cd7 this is the result of serialize, i have saved it to a file, then i do (deserialize (slurp "/tmp/file")), i got java.lang.ClassCastException: java.lang.String cannot be cast to [B
04:57clgvperses: anyway you wont be happy with java serialization for clojure datatypes
04:58Anderkentperses: oh, you can't just print a byte array
04:58Anderkentneither can you slurp something and pass it to readObject
04:59clgvperses: you have to write it to a file via a fileoutputstream
04:59clgvperses: so you can skip the bytearrayoutputstream for the file scenario ;)
05:00Anderkentslurp works on text files, so it returns a string; what you want is (require '[clojure.java.io :refer [file output-stream input-stream]) (with-open [out (output-stream (file "path"))] (.write out (serialize "myobj")))
05:00clgvperses: but as I hinted before you'll store a lot of useless internal structure for clojure datatypes when you use serialization
05:00Anderkent(serialization is evil in general and you really shouldnt use it unless you absolutely have to)
05:01clgvAnderkent: nah. I would not go that far. you'd just define a serialization pattern for clojure datastructures. once you got that right it wont change anymore and your are safe ;)
05:01ddellacostano way, serialization is awesome
05:02clgvit's almost equivalent to defining a binary reader/writer for clojure data
05:02ddellacostasays me and my database
05:02Anderkentunless say you put an Exception in your clojure data structures and then java changes the way exceptions are serialized in a patch version upgrade
05:02clgvdelluminatus: :D
05:02Anderkent(totally not looking at https://github.com/elasticsearch/elasticsearch/issues/3145)
05:02clgvAnderkent: well dont do that ;)
05:02Anderkent.. don't use exceptions?
05:02clgvAnderkent: convert it to a clojure map ^^
05:03Anderkentor, you know, use a sane serialization library instead of builtin java
05:03clgvAnderkent: no dont serialize exceptions ;)
05:03ddellacostayeah, I should qualify that, serialization with clojure data structures is a win
05:03clgvAnderkent: yeah. used kryo for that
05:22persesclgv: sorry i got DC
05:22persesclgv: still there?
05:22clgvperses: yes
05:23persesclgv: you told i should use fileoutstream
05:23clgvperses: if you want to serialize to a file, yes
05:23persesyeah
05:23persesperses: so what is the code should be?
05:24clgvreplace yout bytearraystreams with the corresponding filestreams
05:24clgv*your
05:27Anderkentperses: https://www.refheap.com/76981
05:32clgvAnderkent: include the "file" expression in the functions and return the filename in "serialize" then you can roundtrip via -> ;)
05:35Anderkentmaybe, but this way you can send to anything :P
05:38persesAnderkent: i got thread "main" java.lang.RuntimeException: java.lang.Exception: lib names inside prefix lists must not contain periods
05:39persesAnderkent: https://www.refheap.com/76984
05:39Anderkentright, within a ns form its (:require [clojure.java.io :refer [file output-stream input-stream]])
05:40Anderkent(require ' ) is what you use just in a repl when you can't be bothered to use (ns)
05:43FrozenlockUgh... my mouse is dying. I'll need a replacement. Anyone fell in love with a particular model?
05:44Anderkentdepends what you do with it. for just programming / browsing internets i like the vertical ones
05:44FrozenlockIt does look comfortable.
05:46dsrxpshaw, who needs a mouse
05:46FrozenlockI know, right...
05:46FrozenlockEmacs is frowning on me
06:11persesAnderkent: ping
06:11persesi got java.lang.RuntimeException: Unable to resolve symbol: output-stream in this context, compiling
06:12Anderkentperses: did you fix your require form?
06:12Anderkentoutput-stream is in clojure.java.io
06:13perses (require [clojure.java.io :refer [file output-stream input-stream]])
06:13Anderkentit should be :require at the beginning there
06:14Anderkentassuming it's in the ns macro
06:14persesyeah it
06:15persesAnderkent: still get Unable to resolve symbol: output-stream in this context, compiling:
06:15Anderkentpost your code somewhere?
06:18persesAnderkent: http://sprunge.us/JgCd
06:18Anderkentugh that site eating the double quotes is really annoying
06:19Anderkentthat code works for me, what version of clojure are you using?
06:19Anderkent(other than foobar not being a thing, obviously)
06:19clgvAnderkent: string quotes ;)
06:20Anderkentright
06:20clgvI am sold on [clojure.java.io :as io]
06:21persesAnderkent: how can i know?
06:23Anderkentit'll be in your project.clj
06:23Anderkentor the *clojure-version* var
06:23clgv perses: lol. you should specify it as dependency in project.clj
06:24clgv,(clojure-version)
06:24clojurebot"1.6.0"
06:24Anderkent,*clojure-version*
06:24clojurebot{:major 1, :minor 6, :incremental 0, :qualifier nil}
06:24clgvbetter use the function ;)
06:25martinklepschSente is pretty cool: https://github.com/ptaoussanis/sente :O
06:25Anderkentbut function call blahblah overhead blah
06:26clgvyeah thats definitely an application hotspot here :P
06:26Anderkentit is if it's your entire application!
06:27clgvit is not if it is only run once ;)
06:27persesAnderkent: i have "1.3.0"
06:27clgvperses: time to upgrade^^
06:28persesclgv: lein upgrade?
06:29clgvno
06:29clgvperses: change your dependency declaration on clojure in your project.clj
06:29clgv,(use 'clojure.java.io)
06:29clojurebotnil
06:29clgv,(meta #'output-stream)
06:29clojurebot{:ns #<Namespace clojure.java.io>, :name output-stream, :added "1.2", :file "clojure/java/io.clj", :column 1, ...}
06:30clgvwell wont change much. your code should work with 1.3 as well
06:32Anderkentyeah it should work on 1.3. Try cleaning the project, maybe? Dunno.
06:32clgvrepl restart^^
06:56irctchello how I am using a config file to store passwords / keys for DB and connection
06:58clgvirctc: you can use a clojure hashmap in the config file and load it via clojure.edn/read
07:30oskarthanother option is to the store it in ENV keys
07:40fizruk,(clojure.set/union [1 2 3] [1 3 5])
07:40clojurebot#<ClassNotFoundException java.lang.ClassNotFoundException: clojure.set>
07:43clgv,(require 'clojure.set)
07:43clojurebotnil
07:43clgv,(clojure.set/union [1 2 3] [1 3 5])
07:43clojurebot[1 2 3 1 3 ...]
07:43clgv,(clojure.set/union #{1 2 3} #{1 3 5})
07:43clojurebot#{1 3 2 5}
07:43clgv^^
07:43fizrukthanks! and that is a sad result for seqs :(
07:44clgvyeah, you have to make sure to pass sets in there. if I remember correctly there was a discussion about checking for sets in the impl
07:45clgv,(distinct (concat [1 2 3] [1 3 5]))
07:45clojurebot(1 2 3 5)
07:45clgvfizruk: the seq version ^^
07:45fizrukthanks!
07:46fizrukclgv: is there a distinct-by function?
07:47clgvfizruk: no
07:47hyPiRionfizruk: no, which is somewhat bit puzzling.
07:47clgvfizruk: but you can implement it via a hashmap.
07:47clgvfizruk: or group-by + reduce-kv + distinct
07:49clgv,(defn distinct-by [f coll] (->> coll (group-by f) vals (map distinct)))
07:49clojurebot#'sandbox/distinct-by
07:49clgv,(distinct-by :a [{:a 1 :b 2} {:a 2 :b 3} {:a 1 :b 4}])
07:49clojurebot(({:b 2, :a 1} {:b 4, :a 1}) ({:b 3, :a 2}))
07:50clgvoops
07:51owlHowlhi
07:51clgvah lol. forget that approach^^
07:51clgv,(defn distinct-by [f coll] (->> coll (group-by f) vals (map first)))
07:51clojurebot#'sandbox/distinct-by
07:51clgv,(distinct-by :a [{:a 1 :b 2} {:a 2 :b 3} {:a 1 :b 4}])
07:51clojurebot({:b 2, :a 1} {:b 3, :a 2})
07:51owlHowlhow do i insert an item in list and vector?
07:52clgvowlHowl: you cann only "grow" a list or vector but not insert something efficiently in the middle
07:52hyPiRionfizruk: https://www.refheap.com/76995
07:53hyPiRionowlHowl: If you need to insert efficiently into a vector, consider using the RRB-tree.
07:53clgvhyPiRion: where has all the simplicity gone? :P ;)
07:54hyPiRionclgv: out the window, but at least it's lazy :)
07:54owlHowlyea, python is much simpler :P
07:54fizrukhyPiRion: clgv's version is not?
07:54clgvhyPiRion: hm yeah no lazy group-by built-in ;)
07:54hyPiRionfizruk: no, you cannot use clgv's version on infinite lists
07:54fizrukoh, I always forget map is not lazy
07:54hyPiRionfizruk: map is lazy, group-by is not
07:55clgvfizruk: map is lazy, group-by is not
07:55clgvlol :P
07:55hyPiRionclgv: oh wow
07:55hyPiRiongreat minds and all that
07:55owlHowlif i have a list (list 0 2 3) and want to append elemenet 4?
07:55clgv;)
07:55fizrukclgv: really, I though maps were not lazy!
07:55clgvhyPiRion: and laziness to type more than needed ;)
07:55clgvfizruk: that's wrong
07:56clgvfizruk: "mapv" is "eagerly" producing a vector^^
07:56hyPiRionowlHowl: Usually if I want to append to a list, I would do (concat my-list [4]). But if the lists are long, I'd consider replacing the list with a vector and do (conj [0 2 3] 4)
07:57owl-v-hyPiRion: so... vector > list ?
07:57clgv,(mapv #(reduce conj % (range 10)) [() []])
07:57clojurebot[(9 8 7 6 5 ...) [0 1 2 3 4 ...]]
07:58clgv,(mapv #(reduce conj % (range 5)) [(list) (vector)])
07:58clojurebot[(4 3 2 1 0) [0 1 2 3 4]]
07:58hyPiRionowl-v-: If you don't need laziness, then vectors are generally the best option, yes
07:59fizrukclgv: can you give an example of a lazy map?
08:01owl-v-hyPiRion: (def v (conj v 4)) ?
08:01fizrukclgv: I guess map's values can be evaluated lazily, but you have to know all indices in advance to built a map?
08:03hyPiRionowl-v-: yeah, that's possible. Just a small recommendation, if you don't already know it: It's generally a bad idea to redefine `def`fed values.
08:03hyPiRionfizruk: Well, the problem lies mainly within checking for existence and associating new values onto the map
08:03clgvfizruk: (map inc (range)) is lazy
08:04hyPiRionTo check for existence you have to realize the whole map, to assoc a value you have to realize it.
08:04clgvfizruk: you mean a hashmap?
08:04fizrukclgv: I meant Map as structure, yeah
08:04clgvoh well ...
08:04clgvfizruk: there is a library that supports lazy value calculation though...
08:05clgvfizruk: but that wouldnt help here ;)
08:05fizrukclgv: hyPiRion: now I see where I confused you :p
08:05owl-v-hyPiRion: (def v (conj v 4)) this generates list, not vector :(
08:06hyPiRionowl-v-: if you already have a list, then yes. If you want to append to a list, then I'd do (def v (concat v [4])). If you want a vector, do (def v (conj (vec v) 4))
08:06clgvis it a bad idea to have nested "bind"s in clojure.test.check?
08:08fizruk,(#(vals (zipmap (map :x %) %)) [{:x 1 :y 1} {:x 1 :y 2} {:x 2 :y 3}])
08:08clojurebot({:y 3, :x 2} {:y 2, :x 1})
08:08hyPiRionclgv: I do that indirectly through recursive definitions.
08:10clgvwell maybe it is not the nested binds. it might be the vector of vectors that causes an endless loop
08:12fizruk,(#(zipmap (map :x %) (map :y %)) [{:x 1 :y 1} {:x 1 :y 2} {:x 2 :y 3}])
08:12clojurebot{2 3, 1 2}
08:12fizrukis there a function for that? ^
08:12clgvhyPiRion: or my "such-that" predicate is too complicated to generate any samples at all
08:13hyPiRionclgv: yeah, I had an issue where "such-that" didn't generate any results, and henceforth I ended up in an infinite loop that wa
08:13hyPiRionway*
08:14clgvwell gotta split up the predicate on multiple values to multiple predicates on one value each
08:15clgvfizruk: unlikely
08:15fizrukok
08:15clgvI'd go with reduce though. (reduce (fn [m, {:keys [x y]}] (assoc m x y)) {} coll)
08:23clgvhyPiRion: is there a generator to build a vector and have access to the element position?
08:23owl-v-hyPiRion: thanks. I just finished projecteuler.net/problem=1
08:23clgvI need to generate vectors where the generated values at the different positions are smaller than certain constants (per position)
08:23hyPiRionclgv: ...to the element position?
08:24hyPiRionowl-v-: congrats :)
08:24owl-v-hyPiRion: is there way to sum += 1 ?
08:24clgve.g. constants [2 5 -1] and I need vectors where the elements are smaller than those constants
08:24owl-v-hyPiRion: (def sum (+ sum 1)) ?
08:25hyPiRionowl-v-: There is no `+= 1` in clojure, but `a + 1` is usually written `(inc a)`. Though `(+ a 1)` is okay too.
08:26hyPiRionclgv: sounds like a tuple bind
08:26owl-v-hyPiRion: (def sum (+ sum 3)) ?
08:27clgvhyPiRion: but the number of constants (= vector size) is varying...
08:28owl-v-hyPiRion: i guess it's only way for sum+=3
08:28clgvhyPiRion: (apply gen/tuple (map-indexed ...)) should work right?
08:28fizruk,(let [x 2 x (+ x 3)] x)
08:28clojurebot5
08:29hyPiRionclgv: yeah, something like (gen/fmap (apply gen/tuple (map (gen/choose lowest-value (dec %)) [2 5 -1])) vec)
08:29hyPiRionfizruk: yeah
08:51clgvhyPiRion: ah great, I did not now gen/choose before
08:51clgvthat library definitely needs more documentation with examples^^
08:51hyPiRionyeah, true that
08:53clgvhyPiRion: but the function in fmap is suppose to return values not generators, right? that's what the examples in intro.md suggest
08:55zaistewhat's the best way to include a modified library e.g. compojure as a project dependency ?
08:55hyPiRionclgv: fmap takes a function and a generator, and the function converts the output of the generator
08:55hyPiRionso yes
08:56hyPiRionessentially (gen/fmap foo vec) converts the output from the foo generator by calling vec on it
09:11owl-v-how do I if (a==b && a!=c) ?
09:14hfaafb(if (and (= a b) (not= a c)) ... ...)
09:19owl-v-hfaafb: thanks
09:25clgvowl-v-: since you asked that question better read through one of the clojure books or one of the similar online material
09:41`szxzaiste: you mean something like leiningen checkouts? https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies
09:42persesis there a method called exit in clojure to make the program forcelly exits?
09:44mdrogalisperses: (System/exit 1)
09:45persesmdrogalis: what is the best way to handle command arguments?>
09:46mdrogalisperses: Command line arguments?
09:46persesmdrogalis: if i run it as script?
09:46mdrogalisThere's libraries for that, google around, perses.
09:47persesis i want to pass as example input file to handle from inside the clojure project, what is the best way to do this?
09:47owl-v-when I (loop [i 1] (when (< i 10))) how do I break when i==7 ? I would like to keep (< i 10)
09:50owl-v-(loop [i 1] (when (< i 10) ("if i==7: break") (recur (inc i)) )) how do i break?
09:50sgregory_you don't break, you don't don't recur
09:51sgregory_(if (eq? i 7) 0 (recur (inc i)))
09:51sgregory_something like that
09:52clgvowl-v-: you definitely need one of those clojure books...
09:52hyPiRionreplace (< i 10) with (and (< i 10) (not= i 7))
09:52hyPiRionsgregory_: eq? is the wrong lisp ;)
09:52sgregory_yeah yeah yeah
09:52owl-v-sgregory_: o.o
09:52perses*command-line-args* don't work with lein run --file something ?
09:53persesi tried to (println *command-line-args*) but i got nil
09:54hyPiRionperses: with `lein run`, it's the input commands
09:54owl-v-hyPiRion: and how do i then return 'i'?
09:54hyPiRioninput arguments, rather. So like (defn -main [args] ...)
09:54clgvperses: use "--" before your args to notify leiningen that program aruments start after that
09:54hyPiRionowl-v-: if i == 7?
09:55clgvoh right, and what hyPiRion said ^^
09:55persesclgv: lein run -- hello, give me also nil
09:55persesclgv: maybe i understood wrong
09:55sgregory_owl-v-: every expression has a value, so even a loop or if/else returns the last expression as a value
09:55clgvperses: (defn -main [& args] (println args)
09:56hyPiRionperses: *command-line-args* aren't set by `lein run`, they are given as args to the main function
09:56clgvowl-v-: you want code that constantly evaluates to 7?
09:56hfaafb(loop [i 0] (if (= i 7) i (recur (inc i))))
09:57hfaafbremember that `if` returns the second argument if the first argument evaluates to true, the third argument if the first argument evaluates to false
10:13perses,(if true (println "true") (println "false"))
10:13clojurebottrue\n
10:13perseshow can i pass more lines if "if" passed?
10:14persesprintln "true" and another thing
10:14mdrogalisperses: Surround many forms with (do ...)
10:14mdrogalis,(do (prn 1) (prn 2))
10:14clojurebot1\n2\n
10:18jballancperses: do works, but you might also consider refactoring your code so that you don't need more than one line in the if
10:18jballanccould be as simple as extracting a method or using a letfn
10:25reiddraperhyPiRion: clgv: re: more documentation with examples. any idea where that would best live? more stuff in doc/? an examples/ dir?
10:26clgvreiddraper: I asked myself that question since I considered adding some of my generators as example...
10:27clgvreiddraper: but I dont know. other projects like midje use the wiki on github for structured docs
10:27reiddraperclgv: right now i'm steering away from the wiki because it's a separate git repo, and i like having everything versioned together. i could be convinced otherwise though
10:28clgvreiddraper: yeah being tied to github is a downside of the wiki
10:28reiddraperand github does a good job still rendering markdown that's just in a random file: https://github.com/clojure/test.check/blob/master/doc/intro.md
10:28hyPiRionreiddraper: I don't think there has to be a lot of examples, but example usage of common things could probably be in doc/examples.md. Preferably example use of all the generators and all the functions.
10:29reiddraperclgv: so would an 'advanced' generators page page in the docs/ be a good start?
10:29hyPiRionin particular, the choose function isn't mentioned in intro.md
10:29hyPiRion(which was what we discussed)
10:29reiddraperright, good point
10:30reiddraperclgv: hyPiRion and fwiw, my goal is certainly to eventually have documentation that people love, so please don't hesitate to keep pointing out where things can be improved :)
10:30clgvreiddraper: probably. discussions of use of such-that would be great as well, I tried to generate a vector with certain properties which ran into an endless execution... (infinite loop maybe?)
10:30reiddraperclgv: yeah, and i suppose one issue with documentation is sometimes it gets spread out. I believe that is documented in the docstring, but probably not elsewhere
10:31hyPiRionclgv: I actually added an issue related to infinite loops revolving `such-that` because of that :p
10:32reiddraperhyPiRion: yeah just saw. i'm +1 for just changing gen/such-that to have a default limit. which I'd think should be pretty low, maybe after 10x or something
10:32owl-v-i want to do stuff like this python code:
10:32clgvcurrently struggling with finishing the test. I have a working generator (tested on repl) but the for-all code does not do anything it seems
10:32owl-v-def primefactor(a): # primefactor 3 and above
10:32reiddrapersince you really should only be using it for things that are _very_ likely to pass
10:32owl-v- i = 3
10:32owl-v- while i < a/2:
10:32owl-v- if 0==(a % i):
10:32owl-v- return a/i
10:32owl-v- i+=2
10:32hyPiRionowl-v-: please use a pastebin next time (e.g. refheap.com)
10:32clgvowl-v-: very bad idea. use refheap.com please
10:32owl-v-ok
10:34hyPiRionreiddraper: yeah, I tend to fall into that trap myself. Instead of using bind and generating stuff bottom up, I tend to generate top-down and filter out the correct ones. Not surprisingly, that turns out to be inefficient
10:35owl-v-https://www.refheap.com/77008 to https://www.refheap.com/77009
10:37hyPiRionowl-v-: https://www.refheap.com/77010 is a literal translation
10:38clgvreiddraper: from a syntax point of view it would be awesome to have something let-like to build up generators using the generated values of previous generators
10:38reiddraperhyPiRion: cool, well having a pretty low retry-count will help encourage people away from that, i hope?
10:38reiddraperclgv: gfredericks has been working on something that sounds very similar: http://dev.clojure.org/jira/browse/TCHECK-15
10:39hyPiRionreiddraper: yeah, that should definitely encourage people to do it properly
10:40reiddraperhyPiRion: cool, i can either take a stab at that after work today, or if you wanted to make a patch. either works fine for me
10:40hyPiRionAt least they realise that it's inefficient and the performance penalty they pay for it.
10:40hyPiRionreiddraper: I haven't looked at it yet, so feel free to work on it. I have a master thesis to finish as well, so don't worry about me not having anything to do :)
10:41reiddraperhyPiRion: we can provide two arities, one with default times of 10 or so, and another that lets you pass in num-retries
10:41reiddraperhyPiRion: ha, excellent
10:41hyPiRionreiddraper: yeah, that's what I think is sane
10:41reiddrapercool
10:43perses what is the best book to learn clojure from?
10:44hyPiRionclgv: I think I attempted to do something like gfredericks as well https://github.com/hyPiRion/sc-sugar/blob/7f2c4c9d1385d00a382574aaa38e67ae8afabc92/src/com/hypirion/sc_sugar/sugar.clj#L50-L56 -- but the problem is that a good implementation needs to work like let, and that is really difficult due to capturing values, destructuring and all that
10:45circ-user-QGnbpHello
10:46hyPiRionhi there
10:46circ-user-QGnbpQuick question if I have a vector of a map '({:a 1 :b 2} {:a 1 :b 3}). How do I apply a transformations to all b items?
10:46circ-user-QGnbpI am getting a result from the db and would like to transform it to joda time
10:46circ-user-QGnbpany idea?
10:46circ-user-QGnbpbtw I am a newbie in Clojure (but so far loving it)
10:47bhaumanperses: http://pragprog.com/book/shcloj/programming-clojure
10:47circ-user-QGnbpthanks for the info
10:48circ-user-QGnbpI am reading 2 books currently
10:48hyPiRioncirc-user-QGnbp: do you have a function which converts a :b value to a datetime value?
10:48circ-user-QGnbpyes clj-time.coerce/from-date
10:49clgvhyPiRion: interesting
10:49hyPiRioncirc-user-QGnbp: I'd probably do something like this
10:49hyPiRion,(defn from-date [val] (str "joda-date-" val))
10:50clojurebot#'sandbox/from-date
10:50hyPiRion,(map #(update-in % [:b] from-date) '({:a 1 :b 2} {:a 1 :b 3}))
10:50clojurebot({:a 1, :b "joda-date-2"} {:a 1, :b "joda-date-3"})
10:50circ-user-QGnbpI'll give it a try
10:50circ-user-QGnbpthanks for your help
10:50hyPiRionyou're welcome, hope you get it working
10:55persescirc-user-QGnbp: what are the books you currently reading?
10:59circ-user-QGnbp"clojure in action" "the joy of clojure"
10:59circ-user-QGnbp"programming clojure"
10:59circ-user-QGnbpperses
10:59persesthanks man
10:59circ-user-QGnbpthey are good
10:59circ-user-QGnbpbut I need some hands on
11:00persescirc-user-QGnbp: which one you suggest to start with?
11:00persesi'm new
11:00circ-user-QGnbpperses the joy of clojure is very good
11:00circ-user-QGnbpI guess it depends on your background
11:00circ-user-QGnbpbut they are all good books
11:01persescirc-user-QGnbp: i'm come from ruby world
11:01persesnot java
11:02perseswhat do you guys find Go programming relatinve to clojure, i'm they are different approach, but maybe they are same at any points
11:05sgregory_Go is interesting. I like it for the few cases I've used it, but I wouldn't use it for everything. My main use of it is a "Smarter" reverse proxy
11:06sgregory_And for shuffling network bytes around its very pragmattic
11:08sgregory_But writing business-logic in it could be tedious, the abstractions don't lend themselves to that type of thing very well (in my opinion)
11:09sgregory_But besides both having concurrency baked in, they're kind of at opposite ends of the spectrum.
11:09perses_sgregory_: sorry i got DC
11:10sgregory_Go has anonymous functions, but doesn't really use them well.
11:11clgvreiddraper: is there shuffling in test.check?
11:11clgvotherwise I'd just use clojure.core/shuffle
11:12reiddraperclgv: nope, but that would be a good addition, for sure
11:12reiddrapersince you want to avoid using randomness that is not controlled by test.check
11:12clgvreiddraper: background: I have two sets of elements I want to mix together into one collection
11:13clgvreiddraper: yeah, that's why I asked
11:14reiddraperclgv: there are some subtleties with how shuffling should work w/r/t shrinking
11:14clgvreiddraper: yeah I guess you need some measure of sortedness for shrinking
11:15clgvI'll bridge the gap by generating an integer and use that to initialize a random generator used for shufflling for now
11:18reiddraperclgv: if you like, file an issue here http://dev.clojure.org/jira/browse/TCHECK for adding a shuffle generator
11:20gfredericksshrinking a shuffler sounds fascinating
11:21gfredericksshould figure out how many random swaps it takes to get an even distribution and then use a bounded list of swaps
11:22gfredericksor...you could just generate a random permutation and then at each step you can take any of the swaps that get you closer to sorted
11:23clgvreiddraper: together with shuffle we woul get random permutations as well
11:23clgvreiddraper: shall I add that to the ticket as well?
11:23reiddraperclgv: add whatever you think is helpful
11:23dnolen_very cool Om application by one of the Ableton devs, undo/redo and visual history http://jackschaedler.github.io/goya/ (view in Chrome)
11:25hyPiRiongfredericks: I think the latter should work, it may be a big search space.
11:25hyPiRion*but it may be
11:26clgvreiddraper: any minimum requirements for the content of the ticket?
11:26hyPiRionI mean, worst case n! runtime?
11:26reiddraperclgv: nope
11:32reiddraperclgv: thanks for filing that issue
11:37clgvreiddraper: no problem. we all benefit from that feature (hopefully) ;)
11:39gfrederickshyPiRion: did you have some criticism of my for macro earlier?
11:40hyPiRiongfredericks: No, I was just commenting on my own stuff, and just that it's hard to do it right. Haven't peeked into your impl yet
11:41gfredericksokay. mine is perfect and has no problems.
11:41hyPiRionnice
11:41hyPiRionI expected nothing less of you
11:41gfredericksI fixed a problem last night, prior to which it had one problem.
11:44gfredericksI put it in test.chuck so I don't *need* it in test.check anymore I guess
11:45reiddraperi think its still destined for test.check, just may be a week or so until i have time to really understand it
11:48gfredericksreiddraper: no rush
11:52gfredericksit was fun to write; I guess it's sort of a rewriting macro
11:53gfredericksthe vanilla case is pretty simple via bind/fmap, but supporting :let and :when was a big headache until I thought of the rewriting strategy
11:56clgvgfredericks: I wrote a iteration macro for a special-purpose datastructure supporting :let, :when and :while a few months ago. It was more a conditional code generation approach
11:59clgvthe result of the code that the macro generates is tested with test.check for several non-trivial scenarios to make sure it works. :)
12:02gfredericksclgv: cool
12:14clgvdo I have to use gen/resize when building a gen/sized generator recursivly?
12:14seancorfieldClojure style question: "The names of predicate methods (methods that return a boolean value) should end in a question mark. (i.e. even?)." -- do you think that means that a function ending in ? should return a strict boolean (true or false) or is it acceptable to return truthy / falsey?
12:15seancorfield(and I know it only implies "return boolean" -> "ends with ?", not the other way around)
12:16llasramseancorfield: I prefer strict boolean, just because their are many functions which treat `nil` different from `false`
12:16llasrams,their,there,
12:17seancorfieldI had a quick look through the result of (apropos "?") and everything I checked seemed to return a strict boolean... which was partly why I asked... and partly because it came up as a question of style at work.
12:18clgvreiddraper: hyPiRion: how do I generate a vector recursively with test.check? the problem is a generated element will restrict the range for the following ones and so on
12:19seancorfieldWe have some functions at work that are (used as) predicates but they aren't strictly boolean return types (e.g., we have one that tests (#{"set" "of" "special" "values"} some-str) and that's obviously going to return nil or a string - but it's still a "predicate").
12:19hyPiRionclgv: https://github.com/clojure/test.check/blob/master/doc/intro.md#recursive-generators
12:20clgvhyPiRion: I read that. but how can I translate that to a vector/list? is there some generator for cons/conj/list* sematic?
12:22martinklepschamalloy_, thanks for adding that comment here: http://stackoverflow.com/questions/21416917/multiple-regular-expressions-in-clojure :)
12:23seancorfieldAny other opinions on that style question? Perhaps I should ask it on the mailing list...
12:23reiddraperclgv: here's any example: https://gist.github.com/abrooks/e1ed21f7d59f3bd09339
12:24daityaseancorfield: i'd like to hear opinions about that too... we have a couple of similar cases in our clj-webdriver code
12:27clgvreiddraper: thank you. so the trick is to use bind and conj
12:28reiddraperclgv: correct
12:37clgvreiddraper: I tried to translate it to a simpler exmple but something is still wrong, see https://www.refheap.com/77083
12:37reiddraperclgv: i'm afraid i can't look in any detail at the moment
12:38seancorfielddaitya: I posted to the ML with more context / details
12:38daityacool
12:38daityawill track that thread
12:39clgvreiddraper: ok no problem
12:41coventryclgv: When you call (permutation (dec n) ...), aren't you excluding n from the permutation, unless it was chosen on that iteration?
12:41coventry... since you choose the next element with (gen/choose 1 n).
12:41clgvcoventry: right changed that now^^
12:43clgvcoventry: https://www.refheap.com/77083
12:43clgvsomehow the case n=0 seems not to work as expected
12:45mikerodSo I know there are issues out for this, such as http://dev.clojure.org/jira/browse/CLJ-1239; however, is there any good workaround to preserving metadata when doing something like a prewalk?
12:47justin_smithmikerod: if nothing else, you could manually register metadata while walking, and reapply the metadata to the output
12:49coventryclgv: I think you want (if (= 1 n)) rather than zero?, or (range 1 (inc n)). (range 1 n) has only n-1 elements, so your unused is empty at n=0.
12:50clgvcoventry: for n=0 the empty vector is supposed to be returned
12:50mikerodjustin_smith: hmm, what do you mean by "manual register" it?
12:51coventryclgv: Er, sorry, meant "unused is empty at n=1".
12:51justin_smith(if (should-transform o) (let [the-meta (meta o)] (with-meta the-meta (frob o))) o)
12:51justin_smiththat is kinda psuedo-code but not far from being the meat of a postwalk function
12:52clgvmikerod: write a "walk" wrapper that uses clojure.walk/walk and adds metadata to the result. then rewrite all walk derivates you want to use using the walk wrapper
12:52justin_smithbasically any object that isn't sent back out unchanged would need to be checked for metadata, and that metadata would need to be copied to the transformed version
12:52clgvcoventry: damn off by one error.
12:52clgvcoventry: thx
12:52coventrynp
13:00justin_smithmikerod: my args to with-meta above were backward, but otherwise that method of "inheriting" metadata does work in my repl experiments
13:02justin_smithmikerod: https://www.refheap.com/77087
13:03mikerodclgv: justin_smith thanks for the ideas. I'll look into these.
13:04mikerodI'd hope at some point clj chooses to fix up the walk implementation so we get this stuff built into the "core language". :)
13:05justin_smithmikerod: I am not sure the right behavior is always well defined - at least now you have the option of preserving the original metadata, or altering if you see fit that it be altered
13:05clgvmikerod: or someone writes an awesome walk library ^^
13:05mikerodjustin_smith: Yeah, I figured the "tricky" cases are what has kept it in the state it is in
13:06mikerodclgv: true, that'd be fine; now who..hmm...
13:06clgvso finally the test suite is completed and the implementation battle proof. :)
13:06justin_smithmikerod: random example: walking a structure transforming macros to functions invoking that macro, you wouldn't want the part of the var's metadata that declares it a macro
13:06clgvtime to go home :D
13:07mikerodjustin_smith: +1, that is a good example indeed
13:28shafiredid someone make a performance check between jvm6 - jvm8?
13:30jwmis there a better way of doing this: (def mongodbs (into {} (map #(hash-map % mongo-config) [:bhn :ps :sq :la :spool])))
13:30jwmwhere mongo-config is a vector of values
13:30jwmI just want a non lazy map returned of key value pairs that are mongo-config
13:31jwmkey: mongo-config
13:31justin_smithjwm: that does not look right, you need two element vectors for into {}
13:31justin_smiththere is no such thing as a lazy map
13:31jwmit works
13:31stompyj(+ 1 1)
13:31clojurebot2
13:31justin_smithat least not with a default {} map
13:31jwmI was just trying to clean it up
13:31shafire(+ 40 (+ 1 1))
13:31stompyj(clojure.data/diff {:a 1} { :b 2})
13:32jwmok, non lazy sequency
13:32justin_smith,"clojurebot evaluates random things, but comma makes him evaluate a specific thing"
13:32clojurebot"clojurebot evaluates random things, but comma makes him evaluate a specific thing"
13:33justin_smithher? it?
13:34jwmI am just creating a map of key value pairs where the value is the same across all pairs
13:34justin_smithjwm: ahh, hash-map makes a k / v, then that is coerced to a vec by into
13:34justin_smith,(into {} [{:a 0} {:b 1}])
13:34clojurebot{:a 0, :b 1}
13:35justin_smithnow I see how that works
13:36jwmyeah
13:36jwmI actually did that on my own.. new to clojure
13:36jwmjust trying to come up with a shorthand way of doing it
13:36jwmor even shorter hehe
13:36justin_smith,(do (def mongodbs (into {} (map vector [:bhn :ps :sq :la :spool] (repeat mongo-config)))) mongodbs)
13:36clojurebot#<CompilerException java.lang.RuntimeException: Unable to resolve symbol: mongo-config in this context, compiling:(NO_SOURCE_PATH:0:0)>
13:36justin_smithoops
13:36justin_smith,(do (def mongodbs (into {} (map vector [:bhn :ps :sq :la :spool] (repeat :mongo-config)))) mongodbs)
13:36clojurebot{:bhn :mongo-config, :ps :mongo-config, :sq :mongo-config, :la :mongo-config, :spool :mongo-config}
13:37jwmrepeat might be good
13:37justin_smithslightly more concise, and to my eye definitely clearer what it is doing
13:44amalloydoes anyone know what the deal is with irctc? he's sent me two PMs asking for help with clojure. actually he's sent them to my bouncer, since i'm offline at 4AM
13:45llasramMaybe they want help with Clojure?
13:45amalloywell presumably, yes
13:45amalloybut PMing me, specifically, in the dead of night? seems like not the best plan
13:46dbasch‘(zipmap [:bhn :ps :sq :la :spool] (repeat :mongo-config))
13:46dbasch,(zipmap [:bhn :ps :sq :la :spool] (repeat :mongo-config))
13:46clojurebot{:spool :mongo-config, :la :mongo-config, :sq :mongo-config, :ps :mongo-config, :bhn :mongo-config}
13:47llasramYeah, fair enough. Failed attempts at humor aside, I have no additional information to offer
13:47dbaschjustin_smith: that’s more concise to me
13:47justin_smithdbasch: yeah, that is much better
13:48amalloywell, i sent him a $mail. hopefully he'll just ask the channel at 4AM next time
13:48justin_smithamalloy: clearly your advice is the only advice he is interested in. Give him a quote for your consultation rates.
13:49TravisDamalloy: Did the PM wake you?
13:50amalloyno, certainly not. good lord. if i let IRC wake me. man
13:51amalloymy sleep is so much more important than you guys in #clojure are. no offense
13:51TravisDhehe :) That would have been really unfortunate
13:51TravisDhehe ouch! Cold as ice! ;)
13:51VfeI am now sad ; ;
13:54jwmdbasch: definitely the best way.. I was trying to figure out how to repeat zipmap but didn't know about repeat!
13:54jwmthanks guys
13:54dbaschjwm: you’re welcome
14:00justin_smithI frequently forget zipmap because it is so rare I need a map where keys / vals come from two sequences that are generated independently
14:00justin_smithprobably a coding style thing
14:00hiredman.win 15
14:00jwmyeah this is just temporary code anyway
14:01jwmwanted a concise way to map a default vector of config options to db keys in a map
14:01jwm-in a map
14:01jwmI can make my english more concise too hah
14:03jwmits amazing I spent an entire day on this
14:03jwmhehe
14:04arrdemamalloy: haha... good policy. 3am cat pics get old fast
14:06yedii'm having trouble getting my webapp to run with `lein run` or from the compiled uberjar: https://github.com/yedi/reasoned-rhymer/blob/master/project.clj && https://github.com/yedi/reasoned-rhymer/blob/master/src/clj/reasoned_rhymer/handler.clj#L55
14:06yediwhen i use `lein run` it seems to serve an empty webpage
14:07yediwhen i use `java -jar target/reasoned-rhymer-0.1.0-SNAPSHOT-standalone.jar` i get this error: Exception in thread "main" java.lang.NoClassDefFoundError: reasoned_rhymer/handler Caused by: java.lang.ClassNotFoundException: reasoned_rhymer.handler
14:07yediit works fine with `lein ring server` so i think i might be missing something
14:08dbaschyedi: put a (:gen-class) in your handler
14:14yedidbasch: sweet, that fixed the java exception (and now i know a lil more about how java operates with clj)
14:14yedibut now it's behaving like `lein run` and serving an empty webpage
14:17dbaschyedi: client.html should be in resources
14:18dbaschsame path as your .js files
14:24yedidbasch: if i did that, wouldn't i also have to change this line: https://github.com/yedi/reasoned-rhymer/blob/master/src/clj/reasoned_rhymer/handler.clj#L40
14:25justin_smithyedi: yeah, that path should be relative to the resources dir
14:25justin_smithor else the uberjar just won't work
14:33jwmhmm, I'm retarded, how do you run a function over each item in a vector
14:33justin_smithjwm: map or mapv
14:34justin_smithor for
14:34justin_smith,(map inc (range 10))
14:34clojurebot(1 2 3 4 5 ...)
14:34justin_smith,(map inc (vec (range 10)))
14:34clojurebot(1 2 3 4 5 ...)
14:36stompyjjwm: all I know is I just discovered the diff function yesterday
14:36stompyjso I’m right behind you
14:36jwmhah
14:36jwmyeah I have just been copy pasting pretty much
14:36jwmuntil it works
14:36jwm:)
14:37jwmI've got mongodb connected to 5 dbs, smtp server going, web server going, websocket connection and repl inside lighttable going
14:37jwmamazing the power of this setup :)
14:37justin_smithjwm: the repl is great for that. clojure.repl/doc, clojure.repl/apropos, clojure.repl/source
14:37jwmtransitioning from nodejs
14:37jwmyep I use them all
14:37jwmand google hah
14:37justin_smithhttp://clojure.org/cheatsheet also this
14:38yedi"The parser gets the root path from the classloader" --- how would i go about printing that root path?
14:38jwmyep I use that also
14:38jwmI was using doseq vs map
14:38justin_smithyedi: the classpath?
14:39jwmdoseq is what I want to do (I want to run the function on each value of the vector)
14:39justin_smithlein classpath will show the classpath lein would create
14:39justin_smithyou can also introspect on it from a repl...
14:39jwmbut then I realized its not a vector its a map hehe
14:39justin_smithjwm: that works too
14:40justin_smith,(map (fn [[k v]] [(str k k) (inc v)]) {:a 0 :b 1 :c 2})
14:40clojurebot([":c:c" 3] [":b:b" 2] [":a:a" 1])
14:40yedijustin_smith: i think i mean just the file path? i'm basing this off of: https://github.com/yogthos/Selmer/issues/19#issuecomment-26844846
14:40justin_smiththat uses destructuring, in that case it means "name the first and second items of the first arg k and v respectively"
14:41justin_smithyedi: in an uberjar, it is not a file path
14:41justin_smithsince all of your stuff is inside the jar
14:41justin_smitha resource path is just a classpath at the jvm level
14:42yedijustin_smith: ahh i see
14:42yedineed to up my jvm-foo
14:42yedi`lein classpath` appears to be giving me multiple paths however
14:48yediahh i see, it tries to find the resource by looking at all of those paths
14:50justin_smithyes, that is the concept of a path - all the places it checks
14:50justin_smithwell it is an overloaded term - either the specific path at which one thing is found, or the list of places that are checked when looking
14:59lvhHi!
15:00lvhWhat's the thing I use to consume a REST API? clj-http?
15:00yedisuccess! thanks justin_smith
15:01justin_smithyedi: np
15:04tuddlvh: I'm using cljs-ajax
15:04tudddepends if you're consuming from the front or back.
15:05justin_smithtudd: I shudder at the human-centipede concepts that phrase evokes
15:05tuddha
15:07tudddo you know much about Om and banging a REST response onto a channel ... and having it display properly?
15:08tuddwant to continually grab external REST data, drop it in the om-state Atom, and have it re-render automagically
15:12tuddI tend to learn best by example; if there is any of this already done by someone who -actually- knows how to do it "properly"
15:15tuddalso, do you know most idiomatic way to reach into a deeply nested Json doc? (:4th-lvl (:3rd-lvl (:2nd-lvl (:top-lvl response)))) Just doesn't feel like the right way.
15:16AmandaCtudd: (-> response :top-lvl :2nd-levl … )
15:16justin_smithtudd: turn it into clojure data nd use get-in maybe?
15:17justin_smithalso with the "continuous updating" thing, sounds like a good usage of core.async with a sleep / grab data / operate on data loop
15:17justin_smithI am sure there is an example of doing that in om, though I don't have one immediately handy
15:18tuddAmandaC: yeah, thanks. was trying that way... some of the levels, have to get nested nth items of arrays... couldn't get something quite right..
15:19justin_smithtudd: unlike ->, get-in can take numeric indexes
15:19justin_smith,(get-in {:a [0 1 44 3]} [:a 2])
15:19clojurebot44
15:20tuddjustin_smith: want to do exactly that: GET <some_json> -> bang it onto an async channel -> have that assoc into the Om Atom
15:20tuddre-render et voila
15:21justin_smith,(-> {:a [0 2 42 3]} :a (get 2)) ; alternately
15:21clojurebot42
15:21tbaldridgetudd: why not just have get-> swap into om atom?
15:23tuddpulling from different places. was toying around with corraling them into one async chan
15:25tuddtbaldridge: thanks though. yes, one step generally better than three.
15:27tuddjustin_smith: thanks. get-in much more sensible
15:29jwmI love ->
15:33justin_smithtudd: the advantage of -> as opposed to get-in is you can do (nth n) to index a list or lazy-seq, and .accessor to get object slots
15:33justin_smithbut with json you won't need those
15:38lgs32ais there something in om like IDidRender?
15:42dnolen_lgs32a: IDidUpdate is effectively the same thing
16:00bodie_what bot does the ,,(println "stuff") in here?
16:00bodie_,(println "inline eval, that is")
16:00clojurebotinline eval, that is\n
16:01bodie_PircBot
16:01bodie_hmm
16:03gfrederickslazybot does ##(str "inline " "eval")
16:03lazybot⇒ "inline eval"
16:04justin_smith,"maybe this works?" 42
16:04clojurebot"maybe this works?"
16:04justin_smithn/m
16:05coventryOff topic: http://opensslrampage.org/
16:05justin_smithcoventry: feel free to join us on #clojure-social
16:06arrdem~offtopic |is| <reply> #clojure-social is that way sir
16:06arrdemor the bots can still hate me..
16:07grimoire~offtopic |is| <reply> #clojure-social is that way sir
16:07clojurebotAck. Ack.
16:07justin_smith~offtopic
16:07clojurebotTitim gan éirí ort.
16:07justin_smith~offtopic
16:07clojurebotCool story bro.
16:07grimoireclojurebot: offtopic |is| <reply> #clojure-social is that way sir
16:07clojurebot'Sea, mhuise.
16:07grimoire~offtopic
16:07clojurebotHuh?
16:07grimoire~botsmack
16:07clojurebotclojurebot evades successfully!
16:08bodie_lol
16:08justin_smith~botsmack
16:08clojurebotOwww!
16:08grimoirethanks justin :P
16:08gtrak~botsnack
16:08clojurebotThanks! Can I have chocolate next time
16:09grimoireclojurebot: offtopic is <REPLY> #clojure-social is that way sir
16:09clojurebotOk.
16:09grimoirethere we go
16:09arrdem~offtopic
16:09justin_smith~offtopic
16:09clojurebot#clojure-social is that way sir
16:09arrdemmaybe I should just stay grimoire...
16:10justin_smith~botcrack
16:10clojurebotPardon?
16:10justin_smith~botslack
16:13arrdem$mail hiredman y clojurebot blacklist me T_T
16:13lazybotMessage saved.
16:14cmiles74Thank you for sticking it out with them, Melinda!
16:15amalloyi think hiredman /ignores lazybot, arrdem, so that's not going to work very well
16:15arrdemamalloy: T_T
16:15arrdemI suppose I'm one of the lower signal inputs on this chan...
16:30tuddjustin_smith: thanks! your suggestion ( get-in & -> ) has collapsed the LOC I - thought I - need
16:31justin_smithawesome
16:31tuddsimple suggestion. big help.
16:31tuddreadability jumped.
16:34danielszmulewiczdnolen_: ping
16:34dnolen_danielszmulewicz: pong
16:34danielszmulewiczhi David, I was wondering if I can extend js types in core.match like we can with java types.
16:36danielszmulewiczdnolen_: I saw your 2011 talk, http://vimeo.com/27860102, getting my hands dirty with core.match. Thanks by the way.
16:36dnolen_danielszmulewicz: can you be more specific about what you mean?
16:36dnolen_danielszmulewicz: no problem.
16:38danielszmulewiczdnolen_: For Java types, we have an interface IMatchLookup, basically giving us the ability to use java types with core.match. I was wondering if I could extend a js array to do the same.
16:39danielszmulewiczdnolen_: I hope I'm explaining myself.
16:41danielszmulewiczdnolen_: OK, here is my code: https://www.refheap.com/77100
16:41dnolen_danielszmulewicz: IMatchLookup hack isn't needed in ClojureScript
16:41dnolen_that's because ILookup isn't a protocol in Clojure
16:41dnolen_just implement ILookup
16:41dnolen_in ClojureScript and you can do map pattern matching
16:43dnolen_danielszmulewicz: I wouldn't even bother with the conversion, just wrap in ILookup via reify or something like that
16:44danielszmulewiczdnolen_: Could you refer me to a snippet of code? That would be awesome.
16:44dnolen_danielszmulewicz: I don't have a snippet of code handy
16:45dnolen_danielszmulewicz: I found this http://gist.github.com/viebel/8461313
16:46dnolen_danielszmulewicz: but really you need to recursively apply via reify if you want it to work in the nested case
16:46danielszmulewiczdnolen_: Awesome. That should do it. Thanks a lot.
16:47danielszmulewicz(inc dnolen_)
16:47lazybot⇒ 2
17:11mikerodstarting the cider REPL buffer via `cider` command has mysteriously just stopped defaulting to be in `cider-mode`
17:11mikerodso I have to put it in cider-mode manually each time I start, then the hooks apply
17:11mikerodI'm not sure I know how to diagnose where this has gone wrong
17:14mikerodoh, there is this cider-repl-mode now
17:14mikerodhmmm
17:15oinksofthi, what's the equivalent in clojure of an erlang callback module?
17:15oinksofti want to have some generic API
17:15tbaldridgeoinksoft: protocols
17:16oinksofttbaldridge: thanks
17:18oinksofttbaldridge: what about using multimethods w/ defmethod in separate clojure (modules/files/whatever you call them)?
17:18vermaif I am using async channels to trigger modals etc, am I going overboard?
17:18tbaldridgeyeah, that works as well, and is much more flexible, at the expense of peformance,
17:18tbaldridgebut it's not bad
17:18oinksoftok, thanks tbaldridge !
17:19tbaldridgeoinksoft: protocols only dispatch off the type of the first argument. Multimethods can dispatch off anything
17:19oinksofttbaldridge: you're right
17:19oinksofttbaldridge: i'm new to clojure so this is very helpful. somebody i am working with suggested i use multimethods in this small project
17:20oinksofttbaldridge: (as opposed to protocols)
17:20oinksofttbaldridge: i think he figured that it would be easier to correct a poor design implemented w/ multimethods :)
17:20tbaldridgeoinksoft: yeah, as a rule of thumb is probably best to stick with hashmaps and multimethods, switch to protocols when you need something faster
17:21oinksofttbaldridge: that's a useful rule of thumb. is there a collection of such rules?
17:21oinksofttbaldridge: sort of a companion to the style guide
17:22tbaldridgeoinksoft: I'm not aware of any, sadly
17:22oinksoftthanks, OK, thanks again for the advice!
17:22oinksoft*that's OK
17:22tbaldridgeone of the core ideas behind clojure however is that you should start with pure data, and use functions to manipulate that data
17:28stuartsierraoinksoft: For similar suggestions, check out some of Stuart Halloway's presentation videos.
17:40vermaI am doing (in om): (om/button {:type "button" :class "blah" :dataToggle "modal" :dataTarget "#mymodal"} "Click Me!"), but the button appears without the :dataXXX fields in the dom
17:41vermaanyone seen this? inside my modal code I do see :dataDismiss correctly transforming into data-dismiss attributes
17:41verma:className* it was 2 sentences above
17:46coventryverma: Do you mean dom/button? I think you need to prepend the map with #js in that case.
17:48coventryI've mostly used sablono, which lets you use straight maps, but dnolen uses #js in his tutes.
17:55seangroveverma: Yeah, it's not a map, it's supposed to be a js-obj
17:55seangroveYou can use a js literal via #js{:className "class" :style #js{:padding 10}}
17:55seangroveNote that the style must also be a js object for React
18:01danielszmulewiczdnolen_: Actually for javascript arrays I
18:03vermasengrove, sorry I missed that part, I hand-typed it, it does have a #js before it :(, sorry about that
18:03danielszmulewiczdnolen_: sorry about that, I was saying that for javascript arrays it's not ILookup but ISequential that I would need to extend, am I right about that?
18:03danielszmulewiczdnolen_: In order for them to participate in core.match?
18:04vermasengrove: something like this https://gist.github.com/verma/11013981
18:04vermaseangrove: ^
18:04vermawhy my xchat has no auto name completion
18:05seangroveverma: Yeah, that looks good
18:06vermanot sure what's going on :(
18:13arrdemsuggestions for a Linux Java disassembler>
18:13Bronsaarrdem: javap -c :P
18:14arrdemBronsa: facepalm. <3
18:14justin_smitharrdem: gdb does some disassembly
18:15gtrakarrdem: no-disassemble :-)
18:15justin_smithobjdump?
18:16gtrakthough that's more repl-oriented
18:16justin_smithI also see ndisasm (from nasm) recommended
18:16amalloyno-disassemble is more enjoyable to use than javap, because you don't have to aot-compile and then wade through a pile of classfiles
18:17Bronsano-disassemble looks really neat
18:17gtraka quick hack :-)
18:18gtrakbut seems to work well enough
18:18tufti love the reference, too. those were my favorite movies when i was a kid. =)
18:18Bronsaif only I knew about it a few months ago :(
18:18arrdemgtrak: nice tool!
18:18gtrakthanks!
18:18tuftit's the macros of bytecodes
18:19hiredmanno-disassemble requires using an agent, which isn't required, you can just grab the generated bytecode https://gist.github.com/hiredman/6214648
18:20gtrakhiredman: yea.. but then you have to be less lazy :-)
18:20gtrakslightly..
18:21gtrakmaybe I should just steal that and add that to the project?
18:21TimMc,(throw (ThreadDeath.)) ;; Curious about whether this is caught
18:21clojurebot#<ThreadDeath java.lang.ThreadDeath>
18:21arrdemgtrak: hardly steal...
18:22gtraki see no problem having more than one way to skin the cat in there.
18:22arrdem'tis the Lisp Way...
18:23amalloyhiredman: that paste doesn't work for me in clojure 1.6.0: Can't call public method of non-public class: public java.lang.Object clojure.lang.Compiler$DefExpr.eval()
18:23AmandaCI’m thinking of wrapping a REST Api, what would be the most idiomatic way to handle this, where it could have different endpoints?
18:23amalloyi guess you have to be in the clojure.lang package to make that work?
18:24gtrakAmandaC: seen the twitter wrapper? I thought that one was pretty nice to use.
18:24AmandaCgtrak: nope, got a link handy?
18:24hiredmanamalloy: depends what it was changed to, a wallhack may just be the best idea
18:24arrdem$google clojure twitter API
18:24lazybot[adamwynne/twitter-api · GitHub] https://github.com/adamwynne/twitter-api
18:25amalloyit's just public class Compiler {static class DefExpr implements Expr{...}}
18:25arrdemAmandaC: ^^
18:25hiredmanthe code is maybe from around 1.4, so it may take some fiddling to work
18:25gtrakAmandaC: usage: https://github.com/gtrak/quewww/blob/master/src/quewww/twitter.clj#L36
18:25gtrakand further down there's an async impl
18:26gtrakAmandaC: https://github.com/adamwynne/twitter-api/blob/master/src/twitter/api/restful.clj
18:26AmandaCgtrak: ah, what I meant by “different endpoints” is things like different hosts which it’d be accessed on
18:27gtrakstill sounds like a similar sort of macro to me
18:27gtrakpass in an endpoint as an argument
18:29arrdem(inc gtrak)
18:29lazybot⇒ 8
18:29AmandaCthat sounds like it’d lead to a lot of repetition
18:30AmandaCmaybe I just don’t think functional enough
18:30vermaseangrove, couldn't get that to work, so changed it to a :onClick handler which >! to a chan which will trigger the modal :P
18:30gtrakAmandaC: if a namespace isn't the right thing, you could return a bag of functions as a map or something.
18:31gtrakclose over the config. unfortunately, then it's a little harder to reason about, use tooling for..
18:32gtrakessentially, that's why dynamic bindings exist, but we all know how terrible those are..
18:33gtrakin this case it might not be so bad.
18:38yedi_justin_smith: what are you workin on
18:38justin_smithdunno, caribou stuff
18:39justin_smithyedi_: in all seriousness, a blog / friend authentication / commenting system for our caribou web framework
18:40justin_smithyedi_: it is also a proof of concept for my new plugin system extension for caribou
18:49arrdemhum... so why does emitted bytecode preserve var indirection even with ^:static?
18:50yedi_justin_smith: is instrument a clojure shop?
18:50yedi_or primarily clj
18:50justin_smithyedi_: only partially clojure, I may even have to use other languages soon
18:51yedi_you guys are a remote shop
18:51yedi_?
18:52justin_smithnot really, we have one guy in Colarado but he frequently flies back here, and he was local first
18:52justin_smithotherwise it is all local
18:52gtrakarrdem: static's a noop now I think
18:52arrdemgtrak: I'm gonna do a diff in a minute, but a cursory scan seems to indicate minor differences
18:53arrdemgtrak: actually. using ^:static seems to enable use of invokedstatic....
18:53arrdemgtrak: but that's all I've seen so far.
18:53gtrakoh, hm.
18:53yedijustin_smith: oh the map on http://weareinstrument.com/ gave me that impression
18:53arrdemBronsa: ping ^^^
18:53yedii guess it means where you guys are initially from
18:54gtrakarrdem: http://stackoverflow.com/questions/7552632/what-does-static-do-in-clojure
18:54justin_smithyedi: all those people came to PDX
18:54justin_smithyeah
18:55Bronsaarrdem: ^:static is a no-op right now
18:55owl-v-hi
18:56gtrakI trust whatever Bronsa says on this matter :-)
18:56owl-v-i'm trying to convert python code to clojore
18:56justin_smithowl-v-: a noble persuit
18:56owl-v-https://www.refheap.com/77046 to something like https://www.refheap.com/77109
18:56gtrakmaybe clojure-in-clojure is really just a fuzz-tester
18:56arrdemBronsa: hum..
18:57justin_smithowl-v-: that's not how while should be used, for starters
18:57justin_smithor def
18:57Bronsaarrdem: I have absolutely no idea what :static used to do btw. Are you maybe thinking of ^:const?
18:57justin_smithBronsa: http://stackoverflow.com/questions/7552632/what-does-static-do-in-clojure
18:57arrdemBronsa: neg. I'm doing research on the (disabled) ^:static system.
18:58arrdemBronsa: I'll check out ^:const tho.. not something I'm familiar with
18:58hiredmanthat is not correct
18:59Bronsaarrdem: you can avoid Var indirection by marking def[n]s ^:const
18:59hiredmanBronsa: I don't think that is correct either
19:00arrdemwell... I've got a test case here, lets see what the compiler does :D
19:00justin_smithowl-v-: calling def inside the function means that as soon as you use it in two threads, everything breaks. The right way is to have multiple loop / recur bindings that are updated
19:00hiredmanBronsa: I have never used :const, but if I recall how it works correctly, it treats in the value of the def as a constant or "quoted constant"
19:00Bronsahiredman: look at the decompiled code for (defn ^:const x [] 1) (defn y [] (x))
19:01justin_smithowl-v-: also, the while calls should probably be when calls
19:01hiredmanBronsa: if you say so
19:01Bronsahiredman: http://sprunge.us/ViWC
19:01justin_smithhiredman: yeah, I saw it referenced as being an annotation to indicate something should be a primative value and not an object
19:02hiredmanjustin_smith: the top answer on that so post is wrong
19:02vermanot sure what I am screwing up here: https://gist.github.com/verma/11016107 the om/get-state returns the right state as far as I can tell, but set-state is faulting, any ideas?
19:02justin_smithhiredman: OK, that's good to know
19:03arrdemBronsa: confirmed here. good to know...
19:03hiredmanjustin_smith: static just removed the runtime var derefing, similar to what Bronsa is saying :const does
19:03justin_smithOK
19:03hiredmannothing to do with invokePrim
19:03Bronsaarrdem: hiredman unfortunately using ^:const on functions doesn't work for functions that close-over some locals
19:04hiredmanBronsa: putting a let binding around defs is super gross anyway
19:04Bronsahiredman: nice rationalization :)
19:04hiredmanBronsa: how is it rationalizing?
19:05arrdemhiredman: just because it's nasty doesn't mean the compiler can't do something about it. Saying it's nasty is implicitly making an excuse for the compiler's inaction.
19:05arrdem(or that's how I read it)
19:05hiredmanthe various metadata flags are buggy and inconsistent as all get out
19:06hiredman:static is super weird, because everything in core is marked static, but as you know, it does nothing
19:07Bronsahiredman: I agree that it looks gross but there are still cases where it's useful, it could *probably* be made to work if instead of using print-dup+read-string the fn object was retrieved by .getRawRoot on the var in the static init
19:07owl-v-justin_smith: how do i do >> x=1; x+=2; print x; on clojure?
19:07Bronsahiredman: also what arrdem said
19:07nDuffarrdem, what are you looking for in that disassembler? If you wanted something with a nice IR, rather than a pure disassembler, that changes your choices. (If you want to be able to go back from the IR to bytecode, that changes them further).
19:08justin_smithowl-v-: (let [x (atom 1)] (swap! x + 2) (println @x))
19:08justin_smithowl-v-: but usually we find ways to do things without mutation - for example via a recursion with a new binding
19:08hiredmanBronsa: it could definitely be made to work, but then the question is, why have ^:const and ^:static, and why was :static disabled?
19:09Bronsahiredman: arrdem, but anyway I don't even know if :const is supposed to work on fns or if it's just by accident so meh.
19:09hiredmanright
19:09arrdemhiredman: I was talking to tbaldridge and it sounds like there were historical reasons for disabling ^:static not long after it was added.
19:10hiredmanI think it is an accident, and most likely :const should just work on primitives
19:10arrdemhiredman: working through the patch that added ^:static, and it looks like most of it is still in place..
19:10nDuffarrdem, ...for pure analysis purposes, IBM's Wala is quite good (fast, clean, simple). If you want to round-trip from a SSA representation, you might have the misfortune to end up with the hairball of mutable state that is Soot.
19:11arrdemthat's rather unfortunate.. ^:static should have a huge performance impact on function calls.
19:11hiredmanif I recall correctly, when :static did do stuff it didn't pr-str the function object, althought it may have just called a no-arg constructor, so closing over may have not worked there either
19:11Bronsahiredman: I'm looking at the code right now, looks like :static preserved the static types of args
19:12arrdemnDuff: that's probably overkill but I'll look into it. gtrak's hack is working really nicely.
19:12Bronsahiredman: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L3454-L3460
19:13owl-v-how do i remove def in clojure “(def x 3) (if (< x i) (def x i))”?
19:13owl-v-in loop
19:13justin_smithowl-v-: use a loop binding, not a def
19:13hiredmanBronsa: I could be wrong, but isn't that the Expr class for static method interop?
19:14justin_smithowl-v-: def is only for globals
19:14Bronsahiredman: no, that's StaticMethodExpr
19:14BronsaStaticInvokeExpr is for :static
19:14justin_smithowl-v-: and ideally a def is not changed (with a few notable exceptions)
19:15justin_smith,(loop [i 0 j 5] (if (> i j) [i j] (recur (inc i) (dec j)))) ; owl-v-
19:15clojurebot[3 2]
19:15hiredmanBronsa: so it tried to, but it relied on the static types at the call site, and wasn't connected to invokePrim anyway
19:16justin_smithowl-v-: notice that this way there are no "variables" - nothing changes other than bindings
19:16Bronsahiredman: so if I'm not mistaken ^:static removed the var indirection + preserved the static types
19:17gvickersI have a vector of numbers [1 2 3 4 5], what is the most idiomatic way to return a new vector with the last element incremented?
19:17arrdemBronsa: that seems to be the case..
19:18owl-v-justin_smith: (inc i) (dec j) yes... but (/ j 2)?
19:18justin_smithowl-v-: sure, whatever you need to do with the args
19:19justin_smithmake each one a binding in the appropriate place
19:19hiredmanBronsa: sure, that must be why it was removed, in favor of invokePrim
19:19owl-v-?
19:19Bronsahiredman: probably, yeah
19:19hiredmanthe type stuff for it is way too fragile, depending the types at the callsite
19:20justin_smithowl-v-: often in clojure instead of mutable objects you have functions that create bindings based on arguments. instead of changing some variable, you bind an argument and recur
19:20Bronsahiredman: no, it doesn't depend on the types at callsite. it uses the types on :arglists
19:20hiredmanOh
19:20justin_smith,(loop [i 0 j 50] (if (> i j) [i j] (recur (inc i) (/ j 2)))) owl-v-
19:20clojurebot[4 25/8]
19:21Bronsaparams is arglists, args is args at callsites
19:21BronsaI mess that up everytime too
19:21justin_smithowl-v-: inc and dec are not special, it works the same way with any other function
19:21arrdemis it trying to offload the typecheck to the caller...?
19:21hiredmanBronsa: interesting, this is live on commented stuff, I wonder what it looked like when :static was live
19:22justin_smithgvickers: if it is always a vec and not some other sequential type:
19:22justin_smith,(let [vec [0 1 2 3 4 5]] (conj (pop vec) (inc (peek vec))))
19:22clojurebot[0 1 2 3 4 ...]
19:22justin_smitherr... :)
19:22justin_smith,(let [vec [2 3 4 5]] (conj (pop vec) (inc (peek vec))))
19:22clojurebot[2 3 4 6]
19:23justin_smithsilly aggressive truncation
19:23Bronsaarrdem: btw it looks like an approach like invokeStatic (assumed I understood this correctly) should be more robust for removing the var indirection rather than using ^:const
19:23gvickersjustin_smith: thanks that is very clean!
19:23vermawhy would om/get-state work fine and return what's expected, but om/set-state! would blow up on the same owner?
19:23arrdemBronsa: noted and added to the research list
19:23Bronsaarrdem: because it should work fine with fn with closed-overs too
19:23justin_smithgvickers: also peek / pop are constant time, unlike some other options
19:24justin_smithwill not work on lists or lazyseqs or whatever though
19:24vermacontext: https://gist.github.com/verma/11016107
19:34owl-v-justin_smith: i couldn't remove def in second loop https://www.refheap.com/77114
19:35justin_smithOK - one more note - that first loop doesn't actually do anything, you have to bind the result somewhere (likely by pulling it into a let binding)
19:36hiredmanBronsa: well, :static generated static methods, so closed overs wouldn't work
19:37justin_smithowl-v-: also, the recur's args should not be in a vector - it should have two separate args
19:37Bronsahiredman: oh right
19:38Bronsaarrdem: I derped. ^
19:38hiredmanBronsa: you could just get rid of manual :static flagging, do λ lifting and implement any function that doesn't close over anything and is never used as a value as a static method
19:38hiredman(you know, for the clojure compiler you are working on)
19:39justin_smithowl-v-: also, the body of the function should be wrapped in let, so you can bind xx, a and x, and each block should create a new binding in the let form
19:39arrdemhiredman: even if it is used as a value you can still do static lifting..
19:39justin_smith,(let [a 0 b 1] (+ a a a b b)) ; owl-v-
19:39clojurebot2
19:39arrdemhiredman: you just have to have an instance class around that you can pass as a value.
19:39justin_smith,(let [a 1 b 2] (+ a a a b b)) ; owl-v- - slightly less pointless this time
19:39clojurebot7
19:45coventry`owl-v-: You'd probably get a lot out of chapters 3 & 4 of Clojure From the Ground Up: http://aphyr.com/posts/303-clojure-from-the-ground-up-functions
19:47justin_smith(inc coventry) good link
19:48coventry`verma: Have you verified it's failing on that line by deleting it?
20:15vermain om, how do I setup a component local state?
20:15vermaI have a go loop in IWillMount which sets a state variable which is used by a function inside IRenderState
20:16vermadoing a (om/set-state!) in my go loop inside IWillMount is blowing up
20:27seancorfieldverma: you probably want to ask on the #clojurescript channel
20:28seancorfieldverma: but put your code on refheap.com and post the link so we can take a look
20:28vermaseancorfield, thanks, will do
20:28vermaI did put it here: https://gist.github.com/verma/11016107
20:29vermaat least the area I'm having trouble with
20:30coventry`verma: Oh, put the set-state! in did-mount instead.
20:31owl-v-I found this but I don't understand line 2 and 3. https://www.refheap.com/77117
20:31coventry`Probably the whole go block.
20:31vermahttps://www.refheap.com/77118
20:31justin_smithowl-v-: that defines multiple arities for the same function
20:31vermacoventry` I did try that, let me do it again to make sure
20:32justin_smithowl-v-: it decides which one to call based on how many args it gets
20:33vermacoventry`, I tried in did-mount but it fails the same way.
20:34owl-v-justin_smith: lol; is it like function overloading?
20:35justin_smithit is argument count overloading
20:35justin_smithif it gets one arg, the first one is used, if it gets 3 args, the second one is used
20:38seancorfieldverma: exactly how is it failing? what JS errors are you getting in the console?
20:38seancorfieldoh, taking it to #clojurescript
20:38verma:)
20:38jwmcan you do a def inside a defmacro?
20:39arrdemjwm: you can have a macro that writes defs, but defs inside of defs are bad news.
20:41jwmyeah
20:41jwmI just wanted a nice shorthand way to define a bunch of similar globals
20:43amalloyjwm: you can do it by macroexpanding to (do (def ...) (def ...)), with something like `(do ~@(for [...] `(def ...)))
20:43amalloybut if you need a bunch of similarly-named globals to be autogenerated, consider whether they should really all be separate globals at all. perhaps one global containing a map or a list would be better
20:45jwmyeah, I might do a map
20:45jwmI already did a map for my db collection :)
21:03devnIs there something already out there for doing a "fair interleave", where given [2 2], [4 4 4 4], [8 8 8 8 8 8 8 8], you get the least number of repetetive occurrences for each coll?
21:04devnso, maybe an answer would be: [2 4 8 8 4 8 8 2 4 8 8 4 8 8]
21:05devnor [1], [3 3 3], [5 5 5 5 5] => [1 3 5 5 3 5 5 3 5]
21:05justin_smithdevn: that looks like something one would find in an algorithmic music composition toolkit (not that I can name it or point to an impl)
21:05arrdemdevn: sort by length, partition, interleave?
21:06devnarrdem: let me give that a look -- my brains are fried today but i'd like to finish this last bit of work and call it a day
21:07justin_smithdevn: that example with 1, 3, 5 is not the one that eliminates the most repetition, because the 1 could be between two 5s without adding any other repeat
21:07devnyeah, you're totally right
21:08justin_smithnot that I know what the algorithm should be, just going off the constraint you describe
21:08devnno it's a good point, thanks
21:09justin_smithbut then it's not much of an "interleave" - or it is a weird one - if 1 ends up in the middle somewhere like that
21:09devnthe other case i havent written down yet is the case where there are a couple of even colls, [2 2] [3 3] [5 5 5 5 5] => [2 5 3 5 2 5 3 5 5]
21:10justin_smithI think what you describe could be interpreted as a few different kinds of interesting puzzle
21:10devnit's probably a well defined problem. network algorithms
21:11devnthis is really to cut down on hammering a particular host
21:11justin_smithahh
21:11devnbut the set of requests is a known value, and the range of hosts is a known value
21:12devnso you might have like: {"host1.com" 33 "host2.com" 999 "host8.com" 2000}
21:12justin_smithwhat about an iterate that decs the count refered to by some key in a map, preferring to access each at a rate proportional to its count but also avoiding hitting the same one twice in a row
21:12devnit doesnt do a whole lot of good when the values are really far apart
21:12devnbut it's /something/
21:19devnmaybe this would work: https://github.com/overtone/overtone/blob/master/src/overtone/algo/chance.clj#L18
21:19devn,(let [data [1 3 3 3 5 5 5 5 5] freqs (frequencies data) total (count data) pcts (for [[v cnt] freqs] (double (/ v total)))] pcts)
21:19clojurebot(0.1111111111111111 0.3333333333333333 0.5555555555555556)
21:19justin_smithdevn: weighted round robin? http://en.wikipedia.org/wiki/Weighted_round_robin
21:20devnjustin_smith: nice find. thanks. i should have googled round robin.
21:20justin_smitha weighted choose seems like an impl detail for a weighted round robin actually :)
21:22devnthe only issue with what you were saying above is that weighted round robin serves empty packets
21:22devni can pad and interleave with nils, but i am not going to be making empty requests
21:22justin_smithright
21:22justin_smithit's not a perfect mapping, but there are similarities
21:22devnjustin_smith: yeah, i think the weighted choose is just fine
21:23devnthe spacing doesn't need to be perfect, just better than 500000 xs, and then 40000 ys
21:23cddrDoes anyone have examples of really gnarly Java libraries that have been given a makeover with clojure?
21:24justin_smithcddr: you could compare ring to the java stuff it abstracts over, if that's what you mean
21:24justin_smith(ring being a lib for request handling in an http server, java stuff being tomcat or jetty etc.)
21:25cddrThat sort of thing but I didn't think the servlet API is that bad (though admittedly I haven't used it in anger)
21:26justin_smithcddr: it is OK, it is not as nice as ring is
21:26cddragreed
21:26weavejesterPlus, Ring reimplements the parts of the servlet API that aren’t particularly well thought out.
21:27justin_smithor you could compare clojure.java.io to the various low level java stuff you would use otherwise - my only problems are the areas where c.j.io doesn't have coverage
21:27justin_smithand things like expecting a string to be a url instead of making it a byte stream
21:27weavejesterMost of the time Clojure wrappers are around Java libraries that have reasonable APIs.
21:28weavejesterIt’s very hard to deal with Java APIs that are “enterprisey”.
21:28weavejesterUsually it’s easier to rewrite those parts.
21:31cddrThat's interesting. As a lisper, I was slow to look at clojure because where I worked at the time didn't have any Java code...
21:31cddr...and I thought a big part of what was cool about it was that it worked well with one's existing Java codebase
21:32justin_smithI was slow to look at it because of a kneejerk reaction to [#{{}}]
21:32weavejesterFunnily enough, the bracket syntax was one of the things that attracted me to the language.
21:32justin_smithsomehow my reptile brain was like "thos symbols mean scary imperative madness"
21:33llasramcddr: Being able to use Java libraries is a huge advantage. Being able to use Java libraries with well-designed, simple interfaces directly is a huge advantage
21:34llasramcddr: But of course not every Java library has either a simple or well-designed interface
21:36weavejesterClojure tends to be less tolerant of complexity and bad design than Java. The more complex a Java library, the harder it is to build a simple interface to it, and therefore the harder it is to use with Clojure.
21:36justin_smithI may have to master the art of "java as if it were clojure, but I'm not allowed to use clojure" soon :(
21:37justin_smithI'm sure it can be done, but it will suck.
21:37nDuffjustin_smith, ...well, there _are_ employers around that are looking for Clojure folks. :)
21:37hiredmanjustin_smith: write clojure code to generate the java source
21:38justin_smithheh, I like my workplace for now - I just may have to branch out into other languages to stay here
21:38justin_smithhiredman: yeah, I would be more than a little tempted :)
21:38llasramjustin_smith: Would that be for a specific project?
21:39nullptr`whois llasram
21:39llasramhoho
21:39llasramSPIES
21:39justin_smithllasram: we are a web shop. As we move up in the industry (bigger clients, bigger budgets), we are more likely to have to cooperate with their IT demands
21:39arrdemRED SPY IN THE BASE
21:40justin_smithllasram: so it's more a question of MEGASHOECORP only allows java or node on the backend, MEGACOFFEECORP only allows php, etc.
21:40llasramGotcha
21:40justin_smithwhereas we used to say "your cheapest option is to let us build this thing with clojure" and they'd be like "cheap? OK"
21:40llasramnullptr`: http://blog.platypope.org/ :-)
21:41llasramjustin_smith: Yeah, probably a big harder to convince big companies of that TCO-wise
21:42justin_smithllasram: especially when they are leveraging their own ops team - one that "gets" java, but distrusts clojure
21:42cddrYeah there's no getting round the "but nobody here knows clojure" objection
21:42justin_smithbut is smart enough to know your clojure jar is not java (ie. tried to run a static analasys lib on it...)
21:42llasramInteresting
21:43justin_smithwe had one very big client, big budget, where if we could point to a trustworthy third party static analysis tool that worked, we could have kept using clojure
21:44coventry`What did they want to use the tool for?
21:44justin_smithsecurity analysis
21:44justin_smithjava has so much predictable boilerplate, you can actually detect many common security flaws with regexes I guess
21:44justin_smithor something, I half suspect it is all voodoo
21:44justin_smithbut nobody put a clojure label on their voodoo
21:45llasramInteresting. I would have expected that sort of tool to work mostly on bytecode, and thus work "fine" on AOTed Clojure
21:45justin_smithnope
21:45arrdemjustin_smith: I mean... it depends... you can detect some really interesting things using static analysis..
21:45justin_smithno bytecode support
21:45justin_smithand we found no option with bytecode support
21:45arrdembytecode analysis is really hard... you loose a lot of source PL semantics.
21:46justin_smitharrdem: in that case we should really have a provider offering that for clojure - at least one big company would have paid good money for it :)
21:46arrdemjustin_smith: I mean.. if you wanna contract me to haxx on T.A and build such a thing I'll drop out now :D
21:46coventryI wonder how hard it is to retarget the clojurescript compiler to java.
21:46arrdemcoventry: why would you?
21:47justin_smithso that existing java sa tools work
21:47arrdemmmmmm....
21:47coventryI didn't say it's a good idea, just one way to get through the hoop.
21:48justin_smithmaybe the easiest way to get "good" coverage (meaning at least as much coverage as java gets)
21:48arrdemhonestly... you could probably just write a t.a backend that writes Java source..
21:48seangrovecoventry: You were clearly endorsing and recommending - nay, demanding - it be done
21:48seangrove'I wonder' being the key words there
21:48justin_smithI wonder how hard it would be to launch florida into the sun
21:49arrdemjustin_smith: how many boosters do you have?
21:49arrdemjustin_smith: =P
21:49justin_smitharrdem: let me start the kickstarter project and see how far we get
21:49coventryseangrove: Well, if anyone does it, I'll thank them I guess. :-)
21:51justin_smithanyway, yeah, if we had an sa tool for clojure, that would mean more paying clojure jobs, from what I have seen (both paid to make the tool, for usage of the tool, and clojure jobs that open up thanks to availability of the tool)
21:51justin_smithalso, the easier it is for people to learn clojure... because one limiter is the fear of not being able to find another clojure dev in however many years if updates or fixes are needed
21:52devn man, it's been awhile since i've looked at incanter and contrib, but i just found myself in both of those places
21:52justin_smithcontrib?
21:52devnso much buried treasure
21:52clojurebotMonolithic clojure.contrib has been split up in favor of smaller, actually-maintained libs. Transition notes here: http://dev.clojure.org/display/community/Where+Did+Clojure.Contrib+Go
21:52arrdemhahahahah this SA suite claims to detect infinite loops... someone in Marketing needs to learn about the Halting Problem.
21:53justin_smitharrdem: that tells you how low the barrier is for that cash cow :P
21:53arrdemdevn: not really.. I recently read a bunch of old contrib stuff. The valuable bits have all migrated already.
21:53hiredmanjustin_smith: some of that is just age, tools based on pattern recognition need patterns to be established and widespread
21:53devnarrdem: what about the monte-carlo lib?
21:53justin_smithI mean, as long as it doesn't claim to catch "all" infinite loops, they could be technically in the clear
21:54justin_smithhiredman: very good point
21:54justin_smithhiredman: and I think clojure allows for a lot of surface level variation in patterns (being so expressive)
21:54justin_smithwhich makes sa harder, maybe
21:54coventrySo those java s.a. tools actually carry their weight?
21:54devnjustin_smith: yeah, it's not /completely/ ridiculous to say "detects infinite loops"
21:55devnyourkit "detects deadlock"
21:55hiredmanthe linting / sa space around clojure is trending upward, eastwood is great, typed clojure operates in a similar space
21:55arrdemand it is valuable to have taint analysis tools...
21:55devnforgive me, but just so im clear: SA => Software Analysis?
21:55hiredman(I haven't seen anything built on codeq yet though)
21:55justin_smith(not (re-matches #".*(while true .*)" source)) ;detects infinite loops
21:55arrdemdevn: static analysis
21:56devnoh, thanks
21:57justin_smithfun talking, I need to head home
21:57devnso, story: years ago i had a conversation with chouser at strangeloop about how rich was really interested in datalog.
21:57devnhe brought up the idea of queryale programs and analysis
21:57devnthen rich builds datomic, then codeq
21:58devnit seems like there has been some clear intent
21:59coventrydevn: I meant security analysis.
22:00devnhaha
22:00hiredmanI really like the idea of codeq, and setup our ci server at work to import code in to it, but I have yet to come up with an interesting query to run on it
22:00devnthat's been on my mind a lot lately too! :)
22:00arrdemhiredman: symbolic test coverage analysis!
22:00arrdemhiredman: are you covering all slices of tested functions...
22:00devnhiredman: yeah, it's kind of a bummer that's the case. i think it needs to have its model expanded and be able to do sandboxed eval
22:01arrdemhiredman: all kinds of interesting things you can do there.
22:01devni have been waiting for someone to add to the model with something like clojure.tools.analyze
22:01devnso it's not just git
22:02devnbut then again, maybe that's not necessary
22:03devnyou could run some code at every commit where you basically generate metadata as symbols in a separate namespace
22:03devnusing tools like clojure.tools.analyze, etc. -- then you could query that
22:04devn(def more-info-about-a-foobar-fn {...edn...})
22:05devnwhat do you think?
22:07devni killed chat.
22:07arrdemI think you're complecting the evaluator and the source metadata.. if you're in an environment where you want it, just save the entire T.A tree into your Datomic store. Better yet, figure out some mapping of functions to uuids that's relatively static across program versions and devise a way to leverage Datomic's data change model to reflect changes in the analyzed program let alone the source code.
22:10devnarrdem: i think my general line of thinking is: expand codeq's model to allow for evaluation of particular aspects of the source on import.
22:12devndoes that still strike you as totally crazy? i think it'd be really cool if you could boot up codeq and say: "go spelunking in clojure.core" -- it uses tools.analyzer, eval with fuzzing of inputs to fns, etc. to add metadata to each commit
22:13owl-v-how do i loop through string?
22:13arrdemdevn: nope... sounds like the kind of "real" next generation compiler I'd like to see T.A become and Clojure 2.0.0 feature.
22:14devnowl-v-: you mean like this?
22:14devn,(map clojure.string/upper-case "foo")
22:14clojurebot("F" "O" "O")
22:14devn,(apply str (map clojure.string/upper-case "foo"))
22:14clojurebot"FOO"
22:15devn,(for [character "foo"] character)
22:15clojurebot(\f \o \o)
22:17nullptr`,(let [[f o o] "foo"] (str o o f))
22:17clojurebot"oof"
22:18owl-v-thanks. this works. (defn test-palindromic [c] (for [a (str c)] a ))
22:18devnyou can use loop/recur, owl-v- but the way you phrased your question made me think you might be trying to do something like "each"
22:19devn,(doseq [character "foo"] (println character))
22:19clojurebotf\no\no\n
22:19devnif you want "each"
22:29elpizochoiexit
22:34owl-v-how do i reverse string? "123" to "321"?
22:35owl-v-found it: (println (apply str (reverse (str 123))))
22:55owl-v-line 7 and 11 causing problem in this code: https://www.refheap.com/77125
23:02Frozenlockowl-v-: I've only rarely used recur, but shouldn't there be a `loop' somewhere?
23:03owl-v-Frozenlock: This one don't have loop and it works just fine: https://www.refheap.com/77117
23:03alandipertFrozenlock, the function is the recur point in this case
23:04dbaschFrozenlock: that’s how you do recursive functions
23:04dbaschFrozenlock: well, tail-recursive functions
23:08dbaschowl-v-: line 6 calls an array as a function
23:08owl-v-ops! syntax error!
23:08dbaschowl-v-: I assume that’s not what you intended
23:08dbaschowl-v-: never mind, you’re doing multi-arity
23:08ivanare type annotation warnings supposed to prevent tools.namespace from actually refreshing?
23:08owl-v-((- n1 1) * n2) to (* (- n1 1) n2)
23:08owl-v-:P
23:08ivan(also, no idea how to annotate something as an array of SomeJavaObj)
23:09TEttingerivan: uh... it's complicated
23:09TEttinger^[Lmy.namespace.SomeJavaObj
23:09owl-v-just syntax error which my editor didn't catch...
23:09dbaschowl-v-: also, your comparison is unnecessarily verbose
23:09TEttingerbut better is ^"[Lmy.namespace.SomeJavaObj"
23:09dbasch,(= (apply str (reverse "12321")) "12321")
23:09clojurebottrue
23:09ivanTEttinger: thanks
23:10TEttingeractually uh I don't know if the quotes are a good idea
23:10TEttingerthey might still need reflection if quotes are used, my use of type hints is rusty
23:11TEttinger(but you have a dangling bracket otherwise. stupid opcodes)
23:12TEttingera 2d array of SomeJavaObj is ^[[Lmy.namespace.SomeJavaObj
23:12ivan^"[Ljava.nio.file.LinkOption;" worked
23:12owl-v-dbasch: thanks. that works to with simplicity
23:12notoand I forgot ; right
23:18arrdemhack of the night... <arrdem> hiredman: symbolic test coverage analysis!
23:18arrdem<arrdem> hiredman: are you covering all slices of tested functions... [20:53]
23:18arrdem<devn> hiredman: yeah, it's kind of a bummer that's the case. i think it needs
23:18arrdem to have its model expanded and be able to do sandboxed eval
23:18arrdem<arrdem> hiredman: all kinds of interesting things you can do there.
23:18arrdem<devn> i have been waiting for someone to add to the model with something like
23:19arrdem clojure.tools.analyze
23:19arrdem<devn> so it's not just git [20:54]
23:19arrdem<devn> but then again, maybe that's not necessary
23:19arrdem<devn> you could run some code at every commit where you basically generate
23:19arrdem metadata as symbols in a separate namespace [20:55]
23:19arrdem<devn> using tools like clojure.tools.analyze, etc. -- then you could query
23:19gtrak~guards
23:19clojurebotSEIZE HIM!
23:20Frozenlockarrdem: you should probably paste it on refheap
23:20arrdemGAH
23:20arrdemI'm sorry...
23:21arrdemeh 12 lines coulda been worse
23:21Frozenlockwell, the formatting is terrible :-p
23:22arrdemFrozenlock: it was an accident, new emacs keybindings and the capslock->ctrl remapping have me failing left and right today.
23:22arrdemFrozenlock: I did about 75 lines of garbage in #clojure-social earlier today, now this T_T
23:23Frozenlockarrdem: Time to write some elisp to prevent you from pasting more than 2 lines of text in erc :-p
23:23arrdemFrozenlock: I already turned off flood protection...
23:23arrdemI guess my proxy is providing it's own buffering or something.
23:32FrozenlockAny suggestions for this? https://www.refheap.com/77129
23:33alandipertFrozenlock, i'd put the maps into priority maps and binary search the now sorted-by-value thing
23:34alandipertFrozenlock, https://github.com/clojure/data.priority-map or https://github.com/tailrecursion/cljs-priority-map in cljs
23:35alandipertFrozenlock, actually - disregard. i think i completely misunderstood your question :-)
23:36Frozenlockalandipert: Yeah, I don't think I can do anything with that. But thanks anyway, I was unaware of priority-maps
23:39dbaschFrozenlock: how about something like (partition 2 (interleave (sort-by :a first-col) (sort-by :a second-col))) ?
23:42Frozenlockdbasch: That was my first approach, but there's a problem with that. Say the values are [1 2 3 4] [2 3 4 5], you 'll end up something with 1 and 2 paired together, instead of 2 and 2.
23:42FrozenlockEh, I might have forgot to say that I can drop value if needed. ;-)
23:49dbaschFrozenlock: so in that case you’d want to keep only 2-2, 3-3 and 4-4?
23:50jcrossley3-awaycddr: immutant is chock full of "examples of really gnarly Java libraries that have been given a makeover with clojure", e.g. jms/hornetq, infinispan, quartz, etc
23:51Frozenlockdbasch: Yes. Or keep 1 matched with 200 or whatever (I can just filter it later). But 2-2 should be together, because they are a closest match.
23:53FrozenlockUh... is it me or Cider refuses to have more than a single function definition per entry?