#clojure logs

2016-02-10

00:24tolstoyInteresting. You can't use core.async inside the Electron main thread, it seems. goog.global.setTimeout is not a function.
00:49yuunghey all, how can i load code outside of src/ with lein? i have a folder named db/my_proj in the root of my project folder that I'd like to add to the path
00:50hiredmantolstoy: that sounds like a compilation issue with clojurescript
00:51hiredmangoog.* is the prefix used by the google closure libraries
00:57tolstoyhiredman: I agree. When I'm not so crunched, I'll investigate. It doesn't really make sense to me.
01:25tolstoyhiredman: I wonder if it's because I used :optimizations :simple for an app that runs on node.
01:29neoncontrailsbinjured: did you figure out an answer to your question earlier about generating a type-hinted function?
01:48tolstoyhiredman: If I do this, (set! js/goog.global js/global), things work. ;) http://dev.clojure.org/jira/browse/ASYNC-110
04:19visofhi guys
04:19visof,(conj (vec (drop-last [1 2 3 4])) (inc (last [1 2 3 4])))
04:19clojurebot[1 2 3 5]
04:19visofis this good way to change the last element only in list?
04:20visof,(conj (vec (drop-last [1 2 3 4])) (let [l (last [1 2 3 4])] (* l l l)))
04:20clojurebot[1 2 3 64]
04:21luma,(update [1 2 3 4] 3 inc) ; if you have a vector
04:21clojurebot[1 2 3 5]
04:21luma,(update [1 2 3 4] 3 #(* % % %))
04:21clojurebot[1 2 3 64]
04:22visofluma: what if i don't know index?
04:22visof.indexOf ?
04:22visofwhat if there are multiple same elements?
04:23luma,(update [12 13 14 15] 3 inc) ; this doesn't care about the values, the "3" is the index
04:23clojurebot[12 13 14 16]
04:59jonathanj,(use 'com.rpl.specter)
04:59clojurebot#error {\n :cause "Could not locate com/rpl/specter__init.class or com/rpl/specter.clj on classpath."\n :via\n [{:type java.io.FileNotFoundException\n :message "Could not locate com/rpl/specter__init.class or com/rpl/specter.clj on classpath."\n :at [clojure.lang.RT load "RT.java" 456]}]\n :trace\n [[clojure.lang.RT load "RT.java" 456]\n [clojure.lang.RT load "RT.java" 419]\n [clojure.core$l...
04:59jonathanj:|
04:59jonathanjnot sure if (specter/transform [LAST] inc [1 2 3 4]) is overkill or a good idea
05:00MJB47if you are already using specter i dont see a problem
05:00MJB47but i wouldnt include it to the ns just for that
05:00geirbyyep, the snippet is quite readable
05:01geirbyso go for it if you're already using specter
05:16jonathanjMJB47: thing is that once you have it included, you find ways to use it
05:16MJB47if you have enough cases where it would be useful, then whats wrong with including it?
05:17jonathanji don't know, you were the one suggesting not including it
05:17MJB47the only tradeoffs i can think of is anyoen else working on the project will need to learn it, and its an extra dependency (with all that entails)
05:17jonathanjall i'm saying is that if you include it for "just that" you will almost certainly find a way to use it for other cases
05:17MJB47this is true, but you can always refactor later to do this with the original case
05:18MJB47idk, its up to you
05:18MJB47personally i think the library is awesome and worth including in most projects
05:18MJB47but that varies between people
05:18jonathanjmy personal preference is to do it the other way, once your code is more mature and you only have a few uses of something then perhaps rewrite your code so you don't need it
05:19MJB47that wounds backwards to me
05:19MJB47idk
05:19MJB47sounds*
05:19jonathanjbut in terms of getting things done, including specter and writing the code would have taken less time than the IRC conversation
06:28jonathanjUsing ring-jetty-adapter, how does one specify what certificate to use for SSL connections?
06:29jonathanj(I have a keystore with several certificates in it.)
06:34hillbillietest
07:16justin_smith,(let [v [1 2 3 4]] (conj (pop v) (inc (peek v)))) ; visof
07:16clojurebot[1 2 3 5]
07:17justin_smiththat only works for a vector though
07:17clojurebotCool story bro.
07:17justin_smith,(let [v '(1 2 3 4)] (conj (pop v) (inc (peek v)))) ; visof
07:17clojurebot(2 2 3 4)
10:53fuuduCoderwhat would be the best way to get last but one element in a sequence.
10:54fuuduCoderlast of butlast?
10:55MJB47depends on the type of sequence
10:56MJB47nvm no it doesnt
10:56MJB47probably (last (butlast ...)) yes
10:56aurelian,(map #(nth [1 2 3] %) [0 2])
10:56clojurebot(1 3)
10:57aurelianis there a nicer way to do that? ^^
10:57aurelianselect from a coll a list of indexes
10:57MJB47are you trying to retrieve the first and last elements? or the even indexed elements? or remove the second element?
10:58fuuduCoderjust get the last but one element if it exists
10:58aurelianno, sorry, I have a list and I need to select elements at index 0, 2, 5 and anotherone
10:58aurelianI thought there's a built in
10:58MJB47select-keys is close
10:58MJB47but
10:59MJB47,(vals (select-keys [1 2 3] [0 2]))
10:59clojurebot(1 3)
10:59MJB47you judge if its nicer
10:59averagehat,(map( [1 2 3] ) [0 2])
10:59clojurebot#error {\n :cause "Wrong number of args (0) passed to: PersistentVector"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (0) passed to: PersistentVector"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 28]\n [sandbox$eval76 invokeStatic "NO_SOURCE_FILE" 0]\n [san...
10:59averagehat,(map( [1 2 3] [0 2])
10:59clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
10:59aurelianoh, ok, I thought select-keys is for maps only
10:59averagehatoops sorry clojurebot
10:59averagehat,(map( [1 2 3] [0 2])
10:59clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
11:00averagehat,(map [1 2 3] [0 2])
11:00clojurebot(1 3)
11:00averagehatsorry fail
11:01aurelian,(map #(nth (:a :x 3 :q "foo" :tcp) %) [0 2 5])
11:01clojurebot#<IllegalArgumentException java.lang.IllegalArgumentException: Wrong number of args passed to keyword: :a>
11:01aureliangrr
11:02aurelian,(map #(nth '(:a :x 3 :q "foo" :tcp) %) [0 2 5])
11:02clojurebot(:a 3 :tcp)
11:03jonathanj(specter/select [[0 2]] [1 2 3])
11:03jonathanjsorry, i'm not trying to be that guy who recommends one tool for everything but there seem to be quite a few applicable cases today
12:24novak`is there standard way in clojure to print warnings in console applications?
12:26justin_smithnovak`: you can print to *err*
12:28justin_smithnovak`: for example this works java -jar ~/bin/clojure.jar -e '(binding [*out* *err*] (println "err"))' > /dev/null
12:28justin_smithsince only stdout and not stderr was redirected, "err" prints
12:29bitsynthesishello! is it possible to run leiningen tasks and override a given project property without with-profiles? i'd like to pass in an argument dynamically at the time a task is run
12:31justin_smithbitsynthesis: if I were doing this I would define multiple profiles and use with-profile on the command line to select one
12:31justin_smithI don't know of a way to get freeform config into lein from the cli
12:31hyPiRionbitsynthesis: `lein help update-in`
12:35justin_smithhyPiRion: oh, that's a cool one
12:36bitsynthesisjustin_smith: thank you!
12:45novak`justin_smith: Yep, I've already seen it before somewhere... :D Thank you!
12:55novak`I have one more question - Is there any clojure function that returns platform independent line separator or to use (System/lineSeparator)?
12:56justin_smith,(newline)
12:56clojurebot\n
12:56justin_smiththat outputs it...
12:57justin_smith,@#'clojure.core/system-newline ; var deref since it is private
12:57clojurebot"\n"
12:57justin_smith,System/lineSeparator ; no need for the parens I think
12:57clojurebot#error {\n :cause "Unable to find static field: lineSeparator in class java.lang.System"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to find static field: lineSeparator in class java.lang.System, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :messag...
12:58justin_smitherr...
12:58justin_smith,(System/lineSeparator)
12:58clojurebot"\n"
12:58justin_smithOK then
12:58justin_smithodd that wouldn't be a static field
13:03novak`justin_smith: lineSeparator is method actually
13:04novak`justin_smith: (newline) returns nil, it immediately print newline to *out*
13:07justin_smithnovak`: right, I was surprised lineSeparator was a method not a static field, and as I showed clojure does have a var holding the system-newline, but it's private
13:11novak`justin_smith: So OK, (System/lineSeparator) is good enough. :)
13:12justin_smith,[(Math/PI) Math/PI] ; static methods are slightly weird for hysterical raisins
13:12clojurebot[3.141592653589793 3.141592653589793]
13:13justin_smithit's one of very few places where parens are optional
13:13justin_smithalong with the threading macros, case... anything else?
13:14justin_smithwell case in the special circumstance where you match a single value
13:17novak`\exit
14:12WorldsEndlessWhat's wrong here?
14:12WorldsEndless,(for [[n x] (interleave [1 2] ["keywords.csv" "topics.csv"])] (println n x))
14:12clojurebot#<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: Long>
14:13WorldsEndlessFor some reason for is choking, since the interleave works in isolation
14:13chouserSomething is trying to call 'nth' on a long. Destructuring uses 'nth', so look for a place where destructuring is being unintentionally applied to a number.
14:14WorldsEndlessObviously that would have to be the [[n x]], but I'm not sure why it has a problem here
14:14chouser,(for [[n x] [1 2 3 4]] n)
14:14clojurebot#<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: Long>
14:14chouser,(for [[n x] [[1 2] [3 4]]] n)
14:14clojurebot(1 3)
14:14WorldsEndlessAh. That's it.
14:15WorldsEndlessso, since I want each interleaved item to be an isolated vector pair, what function am I looking for? Maybe not interleave?
14:16WorldsEndlessA nested for loop?
14:16chouserYou might like (map list ...) or (map-indexed list ...)
14:16chouser,(map-indexed list "abcd")
14:16clojurebot((0 \a) (1 \b) (2 \c) (3 \d))
14:16WorldsEndlessSo I don't actually want numbers in the real use case, so maybe some kind of map
14:17chouser,(map list "abcd" "wxyz")
14:17clojurebot((\a \w) (\b \x) (\c \y) (\d \z))
14:17WorldsEndlessyuck
14:17chouser?
14:17WorldsEndlessSorry. I just mean the character iteration surprised me
14:17chouseroh, sorry.
14:17chouser,(map list '[a b c] '[d e f])
14:17clojurebot((a d) (b e) (c f))
14:17chouserbetter? :-)
14:18WorldsEndlessyuep :)
14:18chouserYou may also consider replacing your 'for' with 'map' and save the building and then destructuring of the list.
14:19WorldsEndlessIs there any important difference in this case between map list and map vector?
14:19chouser,(map (fn [x y] (println x y)) '[a b c] '[d e f])
14:19clojurebot(a d\nb e\nnil c f\nnil nil)
14:19chouserbleh. that printed badly.
14:19chouserWorldsEndless: No important difference in this case.
14:19WorldsEndlessI think map is the answer. Thanks!
14:20justin_smithWorldsEndless: for something that's going to be exactly length of 2, list might be slightly better, but it really depends what you plan on using it for
14:20kwladykaWorldsEndless more like you thinking. If you do something for every position in collection use map. With for you can use :let :when etc. and skip some values
14:21chouserha! I snuck an answer in while justin_smith was away! I'll have to go back to lurking now, since I can't actually compete.
14:21justin_smithchouser: hahaha
14:21kwladykachouser yes you was faster this time :P
14:22kwladykait is some kind of achievement ;)
14:45binjuredis there a way to create a var reference that can be used during macro expansion? i keep getting "Can't embed object in code"
14:47justin_smithbinjured: that sounds like you tried to use the var itself instead of its value
14:47justin_smithor the symbol that would look it up
14:49binjuredjustin_smith: yeah, i can't figure out how to give that symbol to the macro in a way that it actually gets used as a var value.
14:49justin_smith,(defmacro silly [] 'foo)
14:49clojurebot#'sandbox/silly
14:50justin_smith,(def foo 1)
14:50clojurebot#'sandbox/foo
14:50justin_smith,(silly)
14:50clojurebot1
14:50justin_smithbinjured: it's that simple
14:50justin_smithor you want the var...
14:50justin_smith,(defmacro silly [] '(var foo))
14:50clojurebot#'sandbox/silly
14:50binjuredhow can i do that without the '? like, programatically. (something-here "foo")
14:50justin_smith,(silly)
14:50clojurebot#'sandbox/foo
14:51binjuredah
14:51justin_smithso you want to take the string, turn it into a symbol, and get the var for that symbol?
14:52binjuredyeah. reason being is earlier in the macro I'm doing (declare (symbol some-string))
14:52justin_smith,(defmacro silly [x] `(var (symbol ~x)))
14:52clojurebot#'sandbox/silly
14:52justin_smith,(silly "foo")
14:52clojurebot#error {\n :cause "clojure.lang.Cons cannot be cast to clojure.lang.Symbol"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.Symbol, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6875]}\n {:type java.lang.ClassCastException\n :message "clojure.lang.Con...
14:52justin_smithergh
14:52binjuredyeah, that's what i get too
14:52justin_smith,(defmacro silly [x] `(var ~(symbol x)))
14:52clojurebot#'sandbox/silly
14:52justin_smith,(silly "foo")
14:52clojurebot#'sandbox/foo
14:52justin_smith~quoting
14:52clojurebotquoting is quote
14:53justin_smith~quote
14:53clojurebothttp://en.wikipedia.org/wiki/Lisp_%28programming_language%29#Self-evaluating_forms_and_quoting
14:53justin_smithI wanted clojurebot to have something clever to say about how stupid quoting always is
14:53binjuredhaha
15:38adissvasta..nidje zive duse
16:01kwladykawhat convention for naming do you have in situation like that: (:require [foo.uuid :as uuid]) (let [bar uuid/create!] ...) <- how you will call bar in this case?
16:02kwladykathe best would be uuid but, uuid is reserved in that situation
16:09kwladykaas i discover i need use uuid in more then one place as name of parameter... maybe in convention better is do require [foo.uuid :as ns-uuid] or something like that?
16:27octei get this "CIDER's version (0.11.0-snapshot) does not match cider-nrepl's version (0.10.0-snapshot). Things will break!" even though i specified "0.11.0-SNAPSHOT" for cider/cider-nrepl plugin in the repl profile in my project.clj
16:27octewhat could i be doing wrong?
16:28octenevermind, i had it my user profile in profiles.clj
16:44kwladykai have strange situation and not sure what is happening, all the time i get expection IllegalArgumentException No matching field found: getSQLState for class java.lang.ClassCastException clojure.lang.Reflector.getInstanceField (Reflector.java:271) <- i am using data from clojure jdbc query and whenever i pass them i have problem like that
16:45kwladykafor example if i pass this data to postal/send-message i get this error, but if i pprint them it is ok.
16:45kwladykathis error totally say mi nothing and is very confuse
16:46kwladykawhat getSQLState have to do with pass data to another function like postal?
16:47kwladykahmm i see whatever i pass to postal it gives me this error.... mmm
16:48kwladykabut i also get this error in not postal, in selmer
16:48kwladykathat is so strange
16:51kwladykaok that was error from postal (as i guess)
16:59patham9hi! why cant clojure automatically detect if a recursion happens at tail position and use recur?
17:00justin_smithpatham9: it totally could and does not. What this avoids is a common bug in other lisps where people do a self call that they assume is optimized but isn't actually tail recursive.
17:01justin_smithpatham9: by requiring you to explicitly say "this must tail recur" you get a compilation error that it is not tail, instead of a sneaky stack overflow later
17:02patham9which is nice yes
17:02patham9then the IDE could be smarter, and insert recur where the recursive call happens in case that it succeeds there ^^
17:03justin_smithpatham9: this would be an awesome editor feature, yes!
17:05patham9another question: it wasn't until Clojure where I really realized the importance of tail recursion
17:06patham9Are there no mechanisms, which can transform a non-tail-recursive formulation into tail recursive ones?
17:06patham9Often not-tail-recursive formulations are a lot more elegant
17:06amalloynot all functions are amenable to such a transformation
17:07amalloyeg, consider doing a depth-first walk of a tree
17:07patham9i see hm
17:07patham9but many could be
17:08kwladykaHow to with-redefs correctly here https://www.refheap.com/114683 ?
17:09amalloyput the with-redefs inside the deftest
17:09kwladykait still call original
17:09kwladykahmm why it doesn't work outside testing?
17:09justin_smithkwladyka: the with-redefs needs to surround your code, right now it only surrounds the def
17:10justin_smithwhen your code runs, it is outside that block
17:10justin_smiththe with-redefs has already exited
17:10justin_smithso you need with-redefs to be inside the deftest
17:10amalloy(with-redefs [...] (deftest ...)) redefines this function, defines a test, and then puts the original function back
17:10kwladykaok i think i undrestand
17:11justin_smithkwladyka: with-redefs is not a lexical binding like let, it is a dynamic one like binding
17:11patham9think about this one: (defn factorial [n] (if (= n 1) 1 (* n (factorial (- n 1) ))))
17:11kwladykaok thank you for explanation
17:11patham9its nearly the most intiutive way how to see it
17:11patham9how to define it
17:12justin_smithpatham9: that one can be tail recursive if you add an arg
17:12justin_smithbut as amalloy mentions some algos can't be recursive that way
17:12patham9if I add an arg?
17:12patham9factorial only has 1 arg ^^
17:12justin_smithright, an accumulator representing an accumulated state
17:12patham9you mean a nested function (loop usually in clojure)
17:13justin_smithpatham9: * has two args, if you want to tail recur both need to be passed to the next call
17:13justin_smithpatham9: no
17:13patham9which has an additional accumulator
17:13justin_smithpatham9: ok sure, an extra arity, a loop, whatever, but hte point is the algo can be tail recursive if you add an argument
17:14justin_smiththat's the general thing - many primitive recursions become tail recursions by adding arguments, but only if you can commute on the accumulator
17:14patham9by using a loop which is quite unelegant, thats what i want to avoid
17:14justin_smithyou can commut * but you cannot commute a tree walk
17:14justin_smithpatham9: then don't use a loop, define a second arity to the same function
17:14kwladykahow do you make function to do nothing with with-redefs: [advertisements.email.handler/send-email! (fn [& _] nil)] <- something like that or can i do it simpler?
17:14patham9can you give an example?
17:15justin_smith(defn factorial ([n] (factorial n 1)) ([n acc] ...))
17:15justin_smiththat way you can update the accumlator on each call, instead of leaving a multiply hanging for later
17:16justin_smith,(defn factorial ([n] (factorial n 1)) ([n acc] (if (= n 1) acc (factorial (dec n) (* acc n)))))
17:16clojurebot#'sandbox/factorial
17:17justin_smith,(factorial 6)
17:17clojurebot720
17:17patham9this works? nice :D
17:18justin_smithonly if your state is commutative, but yes
17:18justin_smithor am I wrong about that? puzzling it out now...
17:18patham9what does it mean to the state to be commutative?
17:19kwladykaanyway for better performance you should use recur
17:19justin_smithpatham9: multiplication commutes, so you don't need to save up all the multiplications for later, you can do them as you go
17:19ptisnovs,(defn factorial ([n] (factorial n 1M)) ([n acc] (if (= n 1) acc (factorial (dec n) (* acc n)))))
17:19clojurebot#'sandbox/factorial
17:19ptisnovsits better, not overflow ;)
17:19ptisnovs,(factorial 100)
17:19clojurebot93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000M
17:19justin_smithptisnovs: you want *'
17:19patham9this multi arg is extremely nice in that language!!
17:19justin_smithor maybe not?
17:19justin_smithpatham9: yeah, it works nicely in clojure
17:19ptisnovsjustin_smith: yeah, it's even better
17:19patham9haskell doesnt have sth like this?
17:19kwladykapatham9 http://clojuredocs.org/clojure.core/recur
17:20justin_smithptisnovs: instead of 1M you can use *' which means it auto-promotes but only as needed
17:20kwladykathere is even example with factorial ;)
17:20justin_smithpatham9: haskell only allows functions of a single argument, of course
17:20justin_smithkwladyka: it is the classic, after all
17:20patham9@kwladyka: loop is not that beautiful ^^
17:22kwladykapatham9 you don't have to use loop
17:22patham9in java i would also use the loop ^^
17:22kwladyka,(defn foo [n] (if (zero? n) "end" (recur (dec n))))
17:22clojurebot#'sandbox/foo
17:22kwladyka,(foo 3)
17:22clojurebot"end"
17:23kwladykapatham9 recur matter for performance
17:24patham9i know
17:24patham9recur is fine
17:24patham9having to create virtual accumulator variables to make sth tail recursive, not so
17:24justin_smithpatham9: it's just moving data from the stack into the heap
17:25patham9the beauty of the representation is the key difference for me
17:25patham9sth beautiful turning ugly to be efficient
17:25ptisnovspatham9: IMHO only primitive recursive functions could be written by using recur + accumulator. for not primitive recursive functions, stack or other data structure would be needed
17:26patham9hm
17:26ptisnovspatham9: https://en.wikipedia.org/wiki/Primitive_recursive_function if you are interested
17:26rcassidyaccumulators aren't ugly :)
17:29patham9interesting
17:29patham9they should be inferred by the compiler not complicating my recursive formulations ^^
17:30justin_smithpatham9: as the page above mentions, it's impossible to solve the general "is this primitively recursive?" quesiton. But it is straightforward to build a function that is guaranteed to be primitive-recursive
17:31patham9maybe in general its hard, for most practical cases though it might be possible
17:32patham9maybe in general its impossible i meant
17:32patham9but this doesnt say that much
17:33patham9as with the halting problem: sure its impossible to decide whether a TM halts. but still its impossible to identify a lot of very interesting infinite classes of TM's where it can indeed be decided
17:33patham9(whether a TM halts in general I meant)
17:33patham9but still its possible to identify... argh ^^
17:34patham9too long day already ^^
17:36patham9but i see I want too much :D
17:37ptisnovspatham9: ackermann's function is pretty good to study: http://rosettacode.org/wiki/Ackermann_function#Clojure
17:37ptisnovspatham9: impossible to avoid the recursion AND not using stack (or vector or so as accumulator)
17:38patham9i know that such functions exist, but most practical recursions are primitive recursive
17:38patham9as occurring in practical programs
17:38patham9but still the compiler wont identify this property and leaves it to the programmer
17:38ptisnovspatham9: yeah (with the exception of traversing trees)
17:40patham9or IDE feature: Primitive recursive function detected, click to rewrite to tail recursive version ^^
17:41patham9this is what i want ^^
17:42ptisnovslisp and scheme could detect some (almost all?) such cases, so it might be possible to implement it
17:44justin_smithwell that's just detecting tail position, not something like "this thing could become an accumulator..."
17:45patham9indeed, it should do the hard work: creating the tail recursive formulation by its own after finding out that the function is primitive recursive ^^
17:48amalloythere are tools that will do that
17:49patham9there are?
17:49amalloywell, i'm thinking of CPS transformers
17:49amalloywhich i think is similar/related
17:52kwladykaWhy in many modules like for example https://github.com/juxt/bidi i see people use vectors instead of map. Like here (def my-routes ["/" {"index.html" :index "article.html" :article}]) <- why not {"/" {...}} ?
17:54justin_smithkwladyka: because the order decides which wildcards could shadow other routes
17:54justin_smithand maps are not ordered
17:55kwladykajustin_smith thx!
17:55justin_smithkwladyka: I figured this out when I helped write a routing lib...
17:58kwladykait was mysterious for me, i saw that many times for different code and always asked myself... but why?
18:06arkhany thoughts on why this doesn't work?: (apply assoc {:a 1} (interpose 0 [:b :c :d]))
18:07justin_smitharkh: interpose only puts items in between
18:07justin_smith,(interpose 0 [:b :c :d])
18:07clojurebot(:b 0 :c 0 :d)
18:07arkhohh ... thank you
18:07justin_smith,(interleave (repeat 0) [:b :c :d])
18:07clojurebot(0 :b 0 :c 0 ...)
18:08justin_smitherr
18:08justin_smith,(interleave [:b :c] (repeat 0))
18:08clojurebot(:b 0 :c 0)
18:08justin_smiththat's the one you want
18:08arkhboom - thank you
18:12amalloy(into {:a 1} (zipmap [:b :c :d] (repeat 0)))
18:13amalloy(into {:a 1} (for [k [:b :c :d]] [k 0]))
18:16arkhnow see, that's where my lengthy but insular clojure experience needs more flavor. I always reach for e.g. apply instead of into and there's probably a bunch of other habits I have like that
18:17arkhit's good to see the different ways
18:21code-apeQuick question, I have a lazy-seq of numbers that does terminate. I want to count how many are even. What's the best way to do this? Thank you!
18:24arkhcode-ape: assuming you don't have memory concerns, (count (filter even? lazyseq)) will do it
18:24arkh,(count (filter even? (range 10)))
18:24clojurebot5
18:25code-apearkh: Cool! ... but I do have memory concerns sadly :/
18:25code-apeSorry, should have specified.
18:30arkhunfortunately I have to take off but in general I would recommend using (loop ...) and iterate through the lazy seq while keeping a tally of even numbers
18:30code-apeThought as much! Thank you.
18:30arkhyou wouldn't need to hold on to the head of the seq or generate an intermediate seq to count over that way
18:31justin_smitharkh: you can use reduce instead of loop for less boilerplate
18:31justin_smitharkh: this holds true with any loop that has exactly one sequence as input and always walks the sequence end to end
18:32justin_smithnb. I am differentiating input from accumulator here
18:33justin_smith,(reduce (fn [n e] (if (even? e) (inc n) n)) 0 [0 1 2 3 4])
18:33clojurebot3
18:34code-apePerfect! Thank you justin_smith :)
18:34amalloy(count (filter even? (range 5)))
18:34amalloyoh i see that's there already, except for some reason you said that memory is a problem?
18:35amalloyit's obviously not
18:35justin_smithamalloy: that doesn't actually do the head holding arkh was talking about does it? right.
18:35justin_smithcode-ape: yeah, the count/filter version is actually fine
18:36code-apeOh, alright, good to know!
18:36justin_smith,(transduce (filter even?) + 0 [0 1 2 3 4 5]) ; fancy-ass transducer version
18:37clojurebot6
18:37justin_smithwait, that adds the items not counting them
18:46amalloyjustin_smith: you need to map constantly 1
18:46justin_smithahh, right
18:46justin_smith,(transduce (comp (filter even?) (map (constantly 1))) + 0 [0 1 2 3 4 5])
18:46amalloy,(transduce (comp (filter even?) (map (constantly 1)) + 0 (range 6)))
18:46clojurebot3
18:46clojurebot#error {\n :cause "Wrong number of args (1) passed to: core/transduce"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (1) passed to: core/transduce"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 32]\n [sandbox$eval73 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox...
18:46amalloywhoops
18:48justin_smithparens are so sneaky
18:48amalloymy success rate of typing stuff into #clojure without paredit is high enough i'm willing to accept the occasional disaster
19:46amalloyhey, speaking of counting the number of items in a collection that satisfy a predicate, i just found this (anonymized) in a codebase at work: (reduce (fn [agg x] (if (pred x) (+ agg 1) agg)) 0 xs)
19:47justin_smithamalloy: it's more general because you could swap out 1 for another number
19:47amalloynice
19:47amalloymultiplication is too expensive for sure
19:53TEttingeramalloy: ... is that a count on a filter, obfuscated?
19:53amalloynaturally
19:54TEttingerit makes me sad
19:54amalloywe were talking about that in here earlier, and someone proposed exactly the same bad solution
20:09TEttingeronly reason I can think of that being useful, amalloy , is if (pred x) could return non-boolean results, so it might add different numbers based on x's value
20:13amalloysure, and then you'd use (apply + (keep #(...) xs))
20:13amalloyyou still wouldn't write it yourself as a reduce
20:35rhg135doesn't apply fail with really long seqs?
20:37amalloyno
20:37amalloy,(apply +' (range 100000))
20:37clojurebot4999950000
20:37rhg135,(apply +' (range 1e100))
20:38clojureboteval service is offline
20:38amalloy1e100? you know how big that is?
20:38rhg135hmm, maybe I had forgotten the +'
20:38rhg135very big
20:39rhg135I doubt I'll ever get a seq over 1e100 long, so all is good
20:42rhg135,(do (def count-with-pred (comp count filter)) (count-with-pred even? (range 1e10)))
20:42clojureboteval service is offline
20:42amalloy1e10 is also really big
20:43amalloythat's why i picked 1e5
20:43rhg135,(do (def count-with-pred (comp count filter)) (count-with-pred even? (range 1e4)))
20:43clojurebot5000
20:43rhg135I need to pick smaller numbers...
20:45rhg135the factorial function is ridiculously easy in clojure
20:45amalloyyeah, the first one you picked is only like...many quintillions of times too big
20:46lambda-11235amalloy, rhg135: (range 1e100) would easily take up all the memory on a supercomputer.
20:47rhg1351e10 isn't even that big though
20:47amalloyno, 1e10 is fine
20:47amalloybut clojurebot doesn't give you that much time
20:47amalloyadding up all the numbers between 1 and 10 billion
20:47amalloytakes more than a couple seconds
20:48rhg135,(iterate (partial * 2) (iterate inc 1))
20:48clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.Iterate cannot be cast to java.lang.Number>
20:48rhg135oh' duh
20:49rhg135yeah, I see how that could take a long time
20:52rhg135I actually calculate the powers of 2 as a inefficient space-heater
22:20binjuredgah, no matter what i try i can't manage to write a macro that generates this: https://gist.github.com/tdavis/d21ac8579e59d9f5049e except where "thing"/"Thing" is dynamic. i can't get a working IDeref to pass to the `recursive` function. it either ends up as a Var object (can't embed object) or a useless Symbol.
22:22amalloyokay, so what are you trying?
22:23binjuredamalloy: i've tried a bunch of stuff. latest attempt is `(intern *ns* ~(symbol name))`, tried that with deref too
22:25amalloy,((fn [vname] `#'~vname) 'thing)
22:25clojurebot(var thing)
22:27binjuredthe problem is building up the contents of that vector requires evaluation (or whatever ~ is called), so i end up with something like [other :- ... #<Var@...> ...]
22:28TEttinger`#'~ of course! how beautifully clear!
22:28TEttingerI'm glad amalloy understands this stuff!
22:28amalloyi mean, you can write (list `var thing) if you prefer
22:29amalloyit's really the same as any other syntax-quoted thing. you start with `, and then write the stuff you want to appear verbatim (here, #'), and then you put a ~ and the stuff you want to be variable
22:31binjuredtried that, it ends up being a PersistentList
22:33amalloybinjured: just like with your question earlier this week, it will be easy to answer once you show me code you are actually running. if you take the things i say, interpret them, apply them, and report results, i have no idea how to help you, because i have no idea how you've interpreted my suggestions, or what context you've put them into
22:33binjuredamalloy: yeah, i'll try to reproduce with a simple example.
22:33amalloyeven a complicated example. if you pasted your entire macro i could fix it in thirty seconds
22:33amalloyi just can't debug guesses
22:52binjuredamalloy: here we go. https://gist.github.com/tdavis/9d8b0f704f1a05f22d0b
22:56amalloyhttps://gist.github.com/amalloy/e2a4edeb7c22b33a9ed5
23:01amalloybinjured: any good?
23:01binjuredamalloy: testing!
23:04binjuredamalloy: goddamn you, i think it worked...
23:04amalloywell i did tell you i knew the answer :P
23:04binjured<3 <3 <3