#clojure logs

2015-05-07

02:23dysfunanyone here reasonably familiar with reagent?
02:25oddcullyjust in case: there is also #clojurescript
02:25dysfunaha
02:33Niachttp://paste.ideaslabs.com/show/K4Qbh2CVIh
02:33Niacwhat's wrong with my loop
02:35NiacIt's for count the length
02:35amalloyNiac: your arguments to recur are in a different order than the loop variables
02:35dysfunwow, you spotted that quickly
02:35dysfuni was still stuck on "is reimplementing primitive function"
02:36amalloywell, also it's off by one
02:36dysfunheh
02:37Niacamalloy: yeah ,that's it
02:38Niacamalloy: i thought it just binding
02:41dysfunincidentally, i'd write that as a reduce, assuming i didn't know count existed
02:42dysfun,(reduce (fn [acc _] (inc acc)) 0 coll)
02:42clojurebot#error{:cause "Unable to resolve symbol: coll in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: coll in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: coll in this context", :at [clojur...
02:42dysfun,(reduce (fn [acc _] (inc acc)) 0 [1 2 3])
02:42clojurebot3
02:43amalloy*shrug* there are lots of reasonable ways to reimplement count. if Niac wants to practice loop instead of reduce, no need to do anything different
02:44amalloydysfun: equally you could write (apply + (map (constantly 1) coll))
02:44dysfunyep
02:45dysfunbut i'm assuming beginner level, and thus we've succeeded in giving him two more ways to do it. go us!
02:51Niacit is cool to use a lisp dialect
02:52dysfunone of the nice things about lisp is everything is pretty simple. and the libraries people have written are pretty simple to use as well
02:54dysfunany ideas why this gives me an error?
02:54dysfun(def from-file (comp ImageIO/read io/file))
02:55dysfun-> Unable to find static field: read in class javax.imageio.ImageIO
02:55dysfunit's definitely there. is it something to do with the polymorphism?
02:57dysfunif i turn it into a function, it seems to work fine
02:58Niacdysfun: is there any idea about pratice the interop with java?
02:58dysfunsorry, i don't understand. you are looking for a way to practice java interop?
02:59Niacdysfun: yes
02:59dysfunfind a java library you like and use it in a project?
02:59dysfunor alternatively write a little library in java and use it from clojure
03:00dysfunbut there's not much to practice. most of my interop code consists only of :import , Class/staticmethod and .method, with the occasional doto thrown in
03:01dysfunif you're stuck for a java library to play with, try doing some image resizing stuff (like i've spent the last day doing). that takes you on a whirlwind tour of AWT and ImageIO and such
03:02Niaci will try
03:02daviidi hope 1 day it will be fully transparent, no more Class/staticmethod and .method
03:03dysfunseems unlikely for several good reasons, not least of which is that it's nice to have a separation between immutable and mutable worlds
03:03daviidhaving to write any java is terrible :) , my 2c
03:04dysfunalthough i've been amused to notice that this image resizing stuff, despite using the java core libraries actually doesn't do any mutation in place. quite by accident
03:52mindbender1What do I do to stop getting no implementation of protocol messages after reloading a namespace?
04:13Niachow to Reverse a Sequence without reverse?
04:16mpenetshuffle and a lot of tries :]
04:17hyPiRion(comp rseq vec)
04:17Niacresq is not allowed too
04:21mpenet(partial reduce conj ())
04:21mpenethairy
04:23mpenetoh well, that's actually what reverse does more or less...
04:27benhudahello
04:28benhudai've left clojure at 1.3 when it was my hobbie go-to, and now want to start integrating it into an R&D org. any highlights for this blackout period? what's the most important things that happened between 1.3 and 1.7 ? (I just finished reading the release notes, but I would appreciate someone who can share personal experience)
04:36hyPiRionbenhuda: Mostly reducers, reader literals, core.async, and now lately transducers. But you can still be productive without them (and don't use them if you don't think they would be valuable)
04:38H4nsis there an operation that "adds" elements to a vector like (the-operation [:foo] 3 :bar) => [:foo nil nil :bar]?
04:38wasamasaoh, clojure got reader literals?
04:39wasamasadidn't know about that
04:39benhudahyPiRion I think core.async is where i left off. i needed async capabilities and i migrated to Go and Node.js
04:40benhuda(primarily disappointed with Nodejs in production and then went doing Go mainly)
04:40benhudaso Clojure is doing well in the async / evented space now?
04:41hyPiRionbenhuda: I haven't done much of it, but apparently it's well designed and heavily used
04:42hyPiRionwasamasa: like #inst, #object, etc
04:42hyPiRion,foo
04:42clojurebot#error{:cause "Unable to resolve symbol: foo in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: foo in this context", :at [clojure.l...
04:42benhudaThanks. one last question - is there a netty based service infrastructure that can challenge Finagle etc ?
04:42benhudalast i check it was Aleph or some sorts
04:48hyPiRionbenhuda: I think you can use Finagle with Clojure directly (like https://www.youtube.com/watch?v=-woCYVaMBsg) but I guess I'd use Aleph for something like that. Not too sure about how it compares to Finagle though.
04:49benhudathanks. so how would you do infrastructure level microservices?
04:51hyPiRionI haven't done microservices in Clojure unfortunately
04:59H4nsit is a popular thing, though. there are a few microframeworks to help with that (based on component, tesla-microservice etc) and there is immutant as the more heavy-weight solution.
05:00H4nsoh. gone.
05:18bcmn
05:39irctcis there an elegant way to fix this situation. I have a chain of fun calls composed with ->> macro. But in between this calls i have the split function which takes (split arg1 #" "). I can not use split inside the macro since macro would put the current argument as the last of the split fun. I would like to have (split #" " arg1)
05:40escherizethere are a few ways, yes.
05:41escherizeone is instead of putting (split #" ") you would put (-> (split #" "))
05:41escherize,(->> "one two" (-> (split #" ")) count)
05:41clojurebot#error{:cause "Unable to resolve symbol: split in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: split in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: split in this context", :at [clo...
05:41escherize,(use clojure.string)
05:41clojurebot#error{:cause "clojure.string", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.ClassNotFoundException: clojure.string, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.ClassNotFoundException, :message "clojure.string", :at [java.net.URLClassLoader$1 run "URLClassLoader.java" 366]}], :trace [[java.net.URLClassLoad...
05:42escherize,(use 'clojure.string)
05:42clojurebot#error{:cause "denied", :via [{:type java.lang.SecurityException, :message "denied", :at [clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69]}], :trace [[clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69] [clojurebot.sandbox.proxy$java.lang.SecurityManager$Door$f500ea40 checkPropertyAccess nil -1] [java.lang.System getProperty "System.java" 708] [su...
05:42escherize,(->> "one two" (-> (clojure.string/split #" ")) count)
05:42clojurebot#error{:cause "java.lang.String cannot be cast to clojure.lang.IFn", :via [{:type java.lang.ClassCastException, :message "java.lang.String cannot be cast to clojure.lang.IFn", :at [sandbox$eval95 invoke "NO_SOURCE_FILE" 0]}], :trace [[sandbox$eval95 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Compiler eval "Compiler.java" 6755] [clojure.core$eval invo...
05:42edbond,(doc clojure.string/split)
05:42clojurebot"([s re] [s re limit]); Splits string on a regular expression. Optional argument limit is the maximum number of splits. Not lazy. Returns vector of the splits."
05:43edbond,(clojure.string/split "a b" #" ")
05:43clojurebot["a" "b"]
05:43edbondescherize, ^
05:43escherizewell said
05:44edbond,(->> "one two" (clojure.string/split #" ") count)
05:44clojurebot#error{:cause "java.lang.String cannot be cast to java.util.regex.Pattern", :via [{:type java.lang.ClassCastException, :message "java.lang.String cannot be cast to java.util.regex.Pattern", :at [clojure.string$split invoke "string.clj" 217]}], :trace [[clojure.string$split invoke "string.clj" 217] [sandbox$eval165 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojur...
05:44edbond,(->> "one two" (-> (clojure.string/split #" ")) count)
05:44clojurebot#error{:cause "java.lang.String cannot be cast to clojure.lang.IFn", :via [{:type java.lang.ClassCastException, :message "java.lang.String cannot be cast to clojure.lang.IFn", :at [sandbox$eval189 invoke "NO_SOURCE_FILE" 0]}], :trace [[sandbox$eval189 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Compiler eval "Compiler.java" 6755] [clojure.core$eval in...
05:44escherize,(->> "one two" ((fn [x] (clojure.string/split x #" ")))
05:44clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
05:45escherize,(->> "one two" ((fn [x] (clojure.string/split x #" "))))
05:45clojurebot["one" "two"]
05:45mpenetwont work like this
05:45mpenet,(macroexpand '(->> "one two" (-> (clojure.string/split #" ")) count))
05:45clojurebot(count (-> (clojure.string/split #" ") "one two"))
05:45mpenet,(->> "one two" (#(clojure.string/split % #" ")) count)
05:45clojurebot2
05:45escherizeright, mpenet
05:46escherizeor, irctc, you could use as->
05:46escherize(as-> "a b" s (str s " " s) (clojure.string/split s #" "))
05:46mpenetyes, as-> is nicer imho
05:47escherizeagree, mpenet
05:47escherizeor if you have a ton of problems with this you can pull out the swiss arrows
05:47escherizehttps://github.com/rplevy/swiss-arrows
05:52irctcthanks as worked
05:53edbond,(doc as)
05:53clojurebotTitim gan éirí ort.
05:53edbond,(doc as->)
05:53clojurebot"([expr name & forms]); Binds name to expr, evaluates the first form in the lexical context of that binding, then binds name to that result, repeating for each successive form, returning the result of the last form."
05:54edbond,(source as->)
05:54clojurebotSource not found\n
05:54escherizeyeah i mixed that up, because when you want -> in the middle of a ->>'d section you can wrap a form with -> to get that once. doesn't work both ways though
05:54irctci have the freedom to put the argument wherever i want. But if have many chains that take it as first parameter, so as seems redundant. But the solution with the ann fun is ugly
05:54irctcdrama!
05:55escherizeyeah
05:55escherizeswiss arrows exactly solves that
05:55irctcBut I have many chains that take it as the first parameter, so as-> seems redundant*
05:56irctcwhat are swiss arrows?
05:56escherizehttps://github.com/rplevy/swiss-arrows#a-generalization-of-the-arrow check the part about default positioning behavior
05:56escherizei think you may want -<> althought there are a lot of arguments against it, IMO
05:57escherizeis there a way to have clojurebot suck in a library off clojars?
05:58irctcI can not even google "-<>" lol
05:58irctcwhat is this
05:58escherizedid my link not go through
05:58escherizehttps://github.com/rplevy/swiss-arrows#a-generalization-of-the-arrow
05:58escherize^
05:58irctcyes, sorry didnt notice it
05:58escherizethat's ok :)
06:01irctcthere should be a macro (rearrange a b (string/split b a)) :D
06:09irctcnice, swiss arrows rock. I feard the would not have the default behaviour of normal ->>. Thanks alot.
06:10escherize:) np
06:34TEttinger(inc escherize)
06:34lazybot⇒ 1
06:34TEttingerswiss arrows are very cool, thanks for linking
06:37escherizeyou made my day TEttinger
06:38TEttingerparallel diamond fishing rod is the best idea for a silly name (even though it seems quite useful!)
07:57CookedGryphonHey, does anyone know how I go about getting permission to use the clojure logo in a blog post? Or is that sort of usage just fine with correct attribution?
08:09puredangerJust the logo itself?
08:11puredangerCookedGryphon: if you're just including it in a blog post as is, you should be fine
08:33CookedGryphonI thought that would be the case, just wanted some reassurance :)
09:08dysfun"clojure.lang.ArityException: Wrong number of args (2) passed to: reader/read"
09:08dysfuncrops up compiling clojurescript, in which i'm not using read myself
09:09Bronsadysfun: you're pulling an older versin of tools.reader than the one cljs requires
09:10Bronsaversion*
09:14dysfunhrm. how can i figure out what's doing that?
09:15dnolendysfun: lein deps :tree
09:15dysfunta
09:17dysfunah, much better. thanks.
09:46kaiyinIs there a way to search the channel logs?
10:00pdurbinkaiyin: they used to be at http://logs.lazybot.org/irc.freenode.net/%23clojure/today.txt but I don't know what happened.
10:00kaiyinpdurbin: I meant to search the logs of all time, or within a certain period, if possible.
10:05tolitiuskaiyin: you can cook something from http://www.raynes.me/logs/irc.freenode.net/clojure/
10:05tolitiusit's partitioned by date, should be trivial to filter/reduce
10:07kaiyintolitius: yeah, I can download them and grep, but a search engine might be a better solution?
10:08tolitiuskaiyin: build it, I'll use it :)
10:08tolitiusthe data is there
10:08pdurbinme too
10:09kaiyinI might need to make a mirror of this site, I guess.
10:10tolitiusyou might want to see what raynes does with lazybot: http://lazybot.org/
10:11tolitiusmaybe a pull request with a "seach" thingy to https://github.com/Raynes/lazybot
10:18acron^is there a form for checking if every element of a list of hasmaps contains the same key-value pair?
10:18acron^,(def k [{:version 1} {:version 1} {:version 1} {:version 1}])
10:18clojurebot#'sandbox/k
10:18acron^,(every? #(= (:version %) (:version (first k))) k)
10:18clojurebottrue
10:18acron^,(def k [{:version 1} {:version 1} {:version 1} {:version 2}])
10:18clojurebot#'sandbox/k
10:19acron^,(every? #(= (:version %) (:version (first k))) k)
10:19clojurebotfalse
10:19acron^seems ugly
10:23chouser(reduce = (map :version k))
10:23acron^perfect :)
10:23acron^thanks
10:24chousernp
10:24acron^hmm
10:24acron^doesn't work :o
10:24chouserheh. Shoulda tested, eh?
10:24acron^,(reduce = '(1 1 1 1))
10:24clojurebotfalse
10:25chouseroh, no, dumb. Try apply instead of reduce
10:25acron^,(apply = '(1 1 1 1))
10:25clojurebottrue
10:25acron^,(apply = '(1 1 1 2))
10:25clojurebotfalse
10:25acron^:)
10:25chouserThat was a last minute substitution in my head. reduce was definitely wrong.
10:46kaiyinin concurrency settings, how do you make sure that at any moment, only one thread is printing stdout?
10:46kaiyinto stdout.
10:47ToxicFrogHave a single thread responsible for printing to stdout and have the other threads send it messages?
10:52kaiyinok, i see.
10:57chouserthat's the Right solution. If you just trying to reduce the likelihood of output interleaving on a single line, you can just (prn-str ...) each thing first, before print'ing and flush'ing it.
10:58kaiyinok
11:16kaiyinwhat is @ for on line 11? https://gist.github.com/kindlychung/7551ac67fe767c769d79
11:17Bronsakaiyin: ~@ is unquote-splicing
11:17Bronsa,`(~[1 2])
11:17clojurebot([1 2])
11:17Bronsa,`(~@[1 2])
11:17clojurebot(1 2)
11:27kaiyinBronsa: yeah, but this is not ~@, it's just @
11:28kaiyinhttps://gist.github.com/kindlychung/7551ac67fe767c769d79#file-future-clj-L11
11:29puredanger@ is a reader macro for deref
11:29puredanger,(doc deref)
11:29clojurebot"([ref] [ref timeout-ms timeout-val]); Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction, returns the in-transaction-value of ref, else returns the most-recently-committed value of ref. When applied to a var, agent or atom, returns its current state. When applied to a delay, forces it if not already forced. When applied to a future, will block if computation n...
11:30tolitius@kaiyin, it is a defer on the future: https://clojuredocs.org/clojure.core/future
11:30tolitius;; When you dereference it you will block until the result is available.
11:30tolitiususer=> @f
11:30tolitiusdone
11:30tolitius100
11:33justin_smithtolitius: s/defer/deref
11:33justin_smithfor deferring things, we have delay
11:34martinklepschIs there a way to destructure for the last element of a sequence?
11:34tolitiusjustin_smith: light for of dyslexia.. :)
11:34justin_smithmartinklepsch: no
11:35tolitiusmartinklepsch: can you revere it and destructure on the first one? :)
11:35justin_smithtolitius: OK, not trying to pick on you, just making sure things are clear
11:35tolitius*reverse
11:35tolitiusjustin_smith: yep, clarity always welcome
11:42justin_smithtoday is a good day: I solved a problem in core.async elegantly by using mult and tap
11:58sobelwoah. i just realized i need tap+mult for something. nice timing.
12:03edbondhow to get all values from chan to coll?
12:06justin_smith(<! (into [] ch))
12:06justin_smithwhere into is core.async/into
12:06edbondjustin_smith, all values I mean read until it's closed
12:06justin_smith"Returns a channel containing the single (collection) result of the
12:06justin_smithitems taken from the channel conjoined to the supplied
12:06edbondjustin_smith, thanks
12:06justin_smithcollection. ch must close before into produces a result."
12:07edbondHave to read doc first
12:07justin_smithsorry for the multi-line paste
12:07edbond,(inc justin_smith)
12:07edbond(inc justin_smith)
12:07clojurebot#error{:cause "Unable to resolve symbol: justin_smith in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: justin_smith in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: justin_smith in th...
12:07lazybot⇒ 251
12:07edbondjustin_smith, Thanks a lot
12:07justin_smithnp
12:21negaduckhere: (def ^:private event-chan (chan)) -- when we put! something and then <!, is the order guaranteed?
12:21negaduckchan is from clojure.async
12:22justin_smithnegaduck: it is guaranteed to give you results in the order the chan got them
12:22negaduckjustin_smith: good
12:22negaduckthanks
12:22justin_smithsometimes the order the chan got the results may be unpredictable when you have real threads :)
12:22negaduckjustin_smith: I need to init things before real threads
12:23negaduckI do this using events
12:23justin_smithOK
12:23justin_smithyeah, a channel is a queue under the hood
12:23justin_smithso that should just work
12:23negaduckok, thanks
12:33timvisheranyone aware of some decent tutorials for `java.jdbc/with-db-transaction`?
12:41gfredericks,(let [{:keys [:foo]} {}] foo)
12:41clojurebotnil
12:41gfredericks,(let [{:keys ["foo"]} {}] foo)
12:41clojurebot#error{:cause "Unsupported binding form: foo", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.Exception: Unsupported binding form: foo, compiling:(NO_SOURCE_FILE:0:0)", :at [clojure.lang.Compiler macroexpand1 "Compiler.java" 6644]} {:type java.lang.Exception, :message "Unsupported binding form: foo", :at [clojure.core$destructure$pb__4915 invoke "core.clj" 4291]}], :trac...
12:53justin_smithgfredericks: that's weird
12:54justin_smith,(let [{:keys [\f]} {}] f)
12:54clojurebot#error{:cause "Unsupported binding form: f", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.Exception: Unsupported binding form: f, compiling:(NO_SOURCE_FILE:0:0)", :at [clojure.lang.Compiler macroexpand1 "Compiler.java" 6644]} {:type java.lang.Exception, :message "Unsupported binding form: f", :at [clojure.core$destructure$pb__4915 invoke "core.clj" 4291]}], :trace [[cl...
13:59chouser,(let [{:keys [:foo]} {:foo 42}] foo)
13:59clojurebot42
14:00Bronsa,(let [{:keys [::foo]} {::foo 42}] foo) ;; < this is why this is supported
14:00clojurebot42
14:00gfredericksoh right
14:00gfredericksI remember now
14:04timvisherah it looks like it might be better to use db-do-commands
14:05timvisheralthough if i'm reading the docs right on that one it needs a series of sql commands and can't just wrap arbitrary statements. which makes sense
14:11timvishernope. that's not quite right either.
14:12timvisherso i have a basic data access layer and two tables that should change in concert (job and job_status). To do that i'm using two different parts of the data access layer, one for each table. i'd like to wrap that in a transaction. what are my options?
14:42timvisheris there something like javadoc for clojure?
14:42timvisheri.e. specially formatted docstrings that could become documentation?
14:42timvisherthe only thing i'm aware of is something like codox but that doesn't do what i'm talking about
14:42wasamasadoesn't the clojure style guide recommend markdown?
14:45timvisherwasamasa: it might. that's not what i mean though. for instance, in javadoc documenting your paramaters is standardized and can become nice markup later.
14:45timvisheri've never seen anything like that for clojure
14:45kaiyinis it possible to use jar files produced by scala? e.g. http://search.maven.org/#search%7Cga%7C1%7Cjhdf5
14:47pbxtimvisher, this is all i can find: http://tomfaulhaber.github.io/autodoc/
14:47amalloykaiyin: java is the lingua franca of jvm languages. scala stuff often has a java-friendly interface, and those are easy to use from clojure
14:48timvisherpbx: i had forgotten about that. looks interesting.
14:48pbxspeaking as someone coming from python who uses sphinx docs a lot, even a de facto standard would be nice to have there
14:51dnolentimvisher: pbx: https://github.com/weavejester/codox
14:51dnolenalso https://github.com/gdeer81/marginalia
14:52timvisherdnolen: i knew about codox. doesn't seem to provide the functionality i'm talking about.
14:53dnolentimvisher: ah formatted docstrings, yeah not aware of anything
14:54timvisherpbx: agreed :)
14:54puredangercodox supports markdown in docstrings
14:55puredangerbut not the equivalent of param definitions
14:55timvisherpuredanger: i don't mean manualy formatting. i mean light-weight markup. like javadoc
14:55timvisheryes :)
14:56timvisherwell... 'light-weight' :)
14:56timvisheri actually quite liked javadoc
14:56pbxi.e. semantic markup
14:56Bronsapuredanger: https://github.com/clojure/build.ci/commit/ed394232d4b407e08ac23758752f2ea3cc6704d2 need a hudson restart when you have a second
14:58puredangerBronsa: in process
14:58Bronsathanks
15:10arohneris there a way to determine if a core.async channel is closed, without taking from it?
15:17edbondhow convert css selector "tr~ tr+ tr" to enlive?
15:20tbaldridgearohner: there's a predicate inside impl that exposes that, but it's not a public api
15:20tbaldridgeChannel/closed? I think it is...
15:20arohnertbaldridge: thanks
15:20arohnertbaldridge: it looks like there's a workaround using alts!!
15:20arohnerbecause it always (?) returns nil if a channel is closed
15:22dfletcherman, comp is a cool function. just wrote my first function that way. who needs a whole new function when you can just jam the old ones together! defn is for suckers :D
15:23wasamasadfletcher: you'lllike juxt
15:36dfletcherhuh having a little trouble thinking of a great use case for juxt wasamasa. comp is easy. the first example I saw showed something like (comp resource input-stream slurp) ... so it's really natural to say "okay what more funcs can I add to the top of this to get the data into a usable state"
15:36dfletcherjuxt - you'd use when you want to compare the output of several algos perhaps?
15:37amalloydfletcher: anytime you want to do two different things to one thing
15:37wasamasasame here
15:38amalloyeg, ##((juxt filter remove) even? (range 10))
15:38lazybot⇒ [(0 2 4 6 8) (1 3 5 7 9)]
15:38wasamasathe most useful example I saw involved using keywords as functions with juxt
15:38amalloywasamasa: that's not a very good example; usually you're better off mapping the hashmap over a list of keywords, vs juxting the keywords together
15:38dfletcherah like ((juxt identity name) :keyword)
15:38dfletcherin the docs
15:38gfredericks((juxt identity deref meta) #'+)
15:38amalloydfletcher: yes, that is a good one. (juxt identity whatever)
15:38gfredericks,((juxt identity deref meta) #'+)
15:39clojurebot[#'clojure.core/+ #object[clojure.core$_PLUS_ 0x52f4db88 "clojure.core$_PLUS_@52f4db88"] {:added "1.2", :ns #object[clojure.lang.Namespace 0x4dedbf2e "clojure.core"], :name +, :file "clojure/core.clj", :inline-arities #object[clojure.core$_GT_1_QMARK_ 0x74d58b91 "clojure.core$_GT_1_QMARK_@74d58b91"], ...}]
15:39pyrdfletcher: i wrote a few words about juxt a while back: http://spootnik.org/entries/2013/05/21_poor-mans-pattern-matching-in-clojure.html
15:41amalloydfletcher: there was a snippet used yesterday, which involved juxt. it's not a good example of code you should actually write, but if you are practicing higher-order functions you may have fun trying to puzzle out what (apply / ((juxt first (partial apply +)) (map (frequencies (repeatedly 1000 #(rand-nth [true false]))) [true false]))) does
15:43dfletcherwhoa pyr you're case matching with an array? neat!
15:43dfletcherthat is a pretty clever use
15:48kaiyinwhat does fn* mean?
15:48amalloykaiyin: it's just a more primitive version of fn. pretend the * isn't there and you'll be fine
15:49kaiyinok
15:51kaiyinwhen is :^once fn* useful? don't we just rely on garbage collection?
15:53dfletcheralright here's one. noticed that lots of core and some third party stuff takes a seq arg and processes them kinda like program args somtimes single somtimes in pairs: [ :random-thing :do-something :id "TheID" :selector ".poo" ] ... etc. is there magic that makes it easy to process these?
15:54chouserI'd recommend against such an api. Just pass in a map.
15:55dfletcheralright fair enough heh.
15:55chouser:-)
15:55chouserI've had to write code to produce such fancy inputs often enough to doubt their value.
16:23Bronsakaiyin: http://clj-me.cgrand.net/2013/09/11/macros-closures-and-unexpected-object-retention/
16:24dfletcherah now that I finished the end of this post pyr this really is a neat trick. overriding funcs using facets of data and it's all super clean. you're letting clojure do the dispatching. very good trick to have in the toolbox.
16:27kaiyinBronsa: hm, look quite complicated.
16:27kaiyinlokks.
16:27kaiyinlooks
16:34Bronsakaiyin: it's not really, observe:
16:34Bronsa,(def a (let [a [1 2]] (^:once fn* [] a)))
16:34clojurebot#'sandbox/a
16:34Bronsa,(a)
16:34clojurebot[1 2]
16:34Bronsa,(a)
16:34clojurebotnil
16:35Bronsakaiyin: :once tells the compiler the fn will be executed only once and thus any closed-over local can be cleared after its use
16:35arrdempuredanger: seeing the above, is such an official lightweight markup in scope for our gsoc minion?
16:36amalloykaiyin: consider something like (let [xs (range 1000000), f (fn [] (last xs))] (f))
16:36puredangerarrdem: explicitly out of scope
16:36arrdemmmkay
16:36amalloyinside of f, the elements of xs are being realized one at a time, but the GC can't throw them away because you still have a reference to f, and might call it again, which would need to re-walk the sequence again
16:36puredangerarrdem: purely to keep scope manageable
16:37puredangerI expect going into that area to open up massive bikeshedding
16:37arrdemyeah for general markup, I'd push for at least a var linking and/or param notation tho
16:38puredangersee, you're starting it :)
16:39arrdemhey if I had my way we'd have a table and example notation :P
16:39arrdemlinking is small fry material
16:39arrdem^{:doc, :fancy-doc}
16:48dfletcher,(str (.substring (clojure.string/join "" (take 10 (repeat (/ 0.0 0.0)))) 0 29) " Batman!")
16:48clojurebot"NaNNaNNaNNaNNaNNaNNaNNaNNaNNa Batman!"
16:48dfletcherlol im such n00b I'm sure that can be shorter.
16:48dfletchercode golf anyone? :>
16:49tbaldridgemost of the string stuff can be replaced by:
16:49tbaldridge.(apply str (take 10 (repeat 0)))
16:49tbaldridge,(apply str (take 10 (repeat 0)))
16:49clojurebot"0000000000"
16:49justin_smith,(apply str (repeat 10 0))
16:49clojurebot"0000000000"
16:49tbaldridgethat too
16:49Bronsa000000000 Batman!
16:49oddcullythanks for putting that song again in my brain. this channel attracts this
16:51justin_smith,(str (subs (apply str (repeat 10 (/ 0 0.0))) 0 29) " Batman!")
16:51clojurebot"NaNNaNNaNNaNNaNNaNNaNNaNNaNNa Batman!"
16:51arrdemheh
16:52escherize,(doc subs)
16:52clojurebot"([s start] [s start end]); Returns the substring of s beginning at start inclusive, and ending at end (defaults to length of string), exclusive."
16:55dfletcherheh it's weird trying to know what funcs might be wrapped and what I have to jump to Java for. guess it will come with expericence.
16:56dfletchersubs++
16:58dfletcheris there a way to use the threading macro when some of the funcs take more than one arg? Tried (-> "foo" #(.something other than else %) bar baz) but it explodes. similar when trying fn.
17:00puredangeryou don't need the #
17:00puredangerwell, assuming the threaded value is the first arg that is
17:00Bronsaif it's the last you can use ->> rather than ->
17:00Bronsaif it's in some random position you can use as->
17:01chouserbtw, beware of subs. Tends to throw exceptions at the slightest provocation.
17:01puredangeror read the multitude of options in this recent thread https://groups.google.com/forum/#!topic/clojure/saeI6tlQ9e8
17:02dfletcherah ty
17:05Fareis there a good portable CL library for globbing?
17:05justin_smithdfletcher: http://conj.io has a good overview
17:05amalloyFare: i imagine this would be the wrong channel to find an answer to that question
17:06Fareoops, wrong channel
17:06Farethanks
17:07Farein a hypothetical clojure-on-cl variant, should false and nil both be NIL, or should a separate value be create for either (and then which)?
17:14amalloyif it were me i'd make them both nil
17:24kaiyin,(into-array (range 1e6))
17:24clojurebot#error{:cause "Java heap space", :via [{:type java.lang.OutOfMemoryError, :message "Java heap space", :at nil}], :trace []}
17:24kaiyin,(into-array (range 1e2))
17:24clojurebot#object["[Ljava.lang.Long;" 0x5c82e9e "[Ljava.lang.Long;@5c82e9e"]
17:25kaiyinhow can i solve this?
17:25puredangersolve what?
17:27arrdemmaking an array larger than main memory?
17:28kaiyinsorry, out of context. https://gist.github.com/kindlychung/455d586af55bb7262407
17:30puredangerint-array ?
17:31puredanger(time (array-sum (int-array (range 400))))
17:32puredangerthere are of course faster ways to make that int-array as the range will create boxed longs
17:32puredangeryou can also get all-unchecked math automatically with: (set! *unchecked-math* true)
17:33puredangeror unchecked math with boxed math warnings with (set! *unchecked-math* :warn-on-boxed)
17:33puredangerthat last only in clojure 1.7
17:39kaiyinpuredanger: what is checked math then, i mean, what is being checked?
17:41puredangeroverflow checks
17:42puredangernormal math ops check and throw exceptions
17:42puredanger,(+ Long/MAX_VALUE 1)
17:42clojurebot#error{:cause "integer overflow", :via [{:type java.lang.ArithmeticException, :message "integer overflow", :at [clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501]}], :trace [[clojure.lang.Numbers throwIntOverflow "Numbers.java" 1501] [clojure.lang.Numbers add "Numbers.java" 1800] [sandbox$eval25 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Comp...
17:42puredanger,(unchecked-add Long/MAX_VALUE 1)
17:42clojurebot-9223372036854775808
17:42puredangerif *unchecked-math* is a truthy value, then you get the latter (faster) behavior
17:43puredangerthere is also +' which checks for overflow and auto-promotes
17:43puredanger,(+' Long/MAX_VALUE 1)
17:43clojurebot9223372036854775808N
17:43kaiyinok, i see.
17:43kaiyinthanks.
17:44puredangermost hot math loops use primitives and unchecked math for fastest perf
17:44puredangeralso, Hot Math, is my new band name
17:44kaiyin:)
17:45kaiyinwhat instrument do you play?
17:45puredangerin decreasing order of you wanting to listen to it: viola, piano, guitar
17:46kaiyinwow, polyglot in music.
17:48tcrayford____periodic PSA for folk running clojure in prod on java 7: upgrade to java 8, java 7 is EOL
17:53ben_vulpeshttps://github.com/samaaron/serial-port << what's the story with the "open" function on this page?
17:55ben_vulpesoh derp i'm a derp.
17:56kaiyinhttps://gist.github.com/kindlychung/6b1e2afd269cd3c074ae according to the "mastering clojure macros" book, there should be a 15x performance boost here, but there isn't.
18:02puredangerdon't always believe what you read, especially when talking about performance :)
18:02oddcullybenchmarking is believing
18:03puredangerrange is faster in 1.7
18:03puredangerand both reduce over range and reduce over arrays is significantly faster (neither uses seqs now)
18:04puredangerwhat difference do you see?
18:06kaiyinI didn't see any.
18:06kaiyinwhat difference do you mean?
18:07puredangerI mean what was the perf difference
18:08puredangerbut you answered that
18:09puredangerthere's both allocation and boxing and checked math involved so it's a muddled comparison regardless
18:10puredangerplus int-array is in there twice which does not seem like the intention, probably meant just y on the last line
18:10kaiyinpuredanger: ah, my bad. will run it again.
18:12tcrayford____also you're likely in a lein repl with most of the jvm opts turned off (which is how lein does by default)
18:12puredangeryes, you'll want :jvm-opts ^:replace ["-server"]
18:12puredangeror something like that
18:13tcrayford____also you're probably benchmarking on a laptop, and it's likely your production hardware isn't a laptop, also you're running the benchmarks in the same jvm (which can really get messed up with the JIT's path dependence), and and benchmarking is nearly always lies
18:14dnolenis there something simpler than this transduce for summing?
18:14dnolen,(transduce (map identity) + 0 [1 2 3])
18:14clojurebot6
18:14puredangerwhy would you use transduce for that?
18:14dnolenpuredanger: imagine that the last arg is not a collection :)
18:15dnolenand transduce knows how to work on such a thing
18:15puredangerso does reduce?
18:15dnolenpuredanger: imagine the last arg is an async process
18:15dnolenand I've written a async-transduce
18:17kaiyinpuredanger: there is indeed a 10x boost: https://gist.github.com/kindlychung/6b1e2afd269cd3c074ae
18:19escherizethe google groups thread that lead to this was very interesting: https://pol.is/7scufp
18:22puredangerdnolen: well map identity should work and not do any allocations but it's still doing a worthless invocation
18:23Bronsapuredanger: dnolen isn't identity a valid transformation function?
18:23dnolen,(transduce identity + 0 [1 2 3])
18:23clojurebot6
18:24Retsamtipis it kosher to mention clojure jobs here? (am a CTO, not a recruiter)
18:24AimHereRetsamtip, I imagine it would be welcomed
18:24dnolenBronsa: right nice because identity will return + which is a valid transformer
18:24Bronsadnolen: what's the point of using transduce if you're not using any transducer though? you're just using it as reduce
18:24oddcullyRetsamtip: in the past, there where jobs posted e.g. once per day
18:25dnolenBronsa: I'm not actually using transduce, I'm using transducers w/ my own async driver
18:25Retsamtipok, if anyone is sensitive to this let me know, thx AimHere
18:26AimHereYeah; your ass is covered. I get the blame for whatever you do next!
18:26Retsamtiphaha
18:26oddcullyAimHere: a killban will tell you
18:26Retsamtipalright- any Clojurists in the NYC area should reach out, My co, Kontor is hiring actively
18:29kaiyinhttps://gist.github.com/kindlychung/cd025ba6b79848cb2168 why isn't this function working?
18:33Bronsakaiyin: line 4, should be (f ret ..) rather than (f init ..)
18:35kaiyinBronsa: ah, i see, thanks! I am just wondering why areduce has to be such a verbose macro: https://gist.github.com/kindlychung/cd025ba6b79848cb2168
18:36kaiyinwith 5 args!
18:36Bronsakaiyin: it has to be a macro rather than a function so that it can avoid boxing/reflection
18:36turbofailyeah if you were using a function version you could just use plain 'ol reduce
18:37turbofailthe only reason you'd use the macro is if you need the extra speed
18:38kaiyinok, where does the avoidance of boxing/reflection occur? Not so obvious.
18:39turbofailbasically the use of the function call in the function version of areduce requires boxing
18:40turbofailthere's no way to use unboxed arguments when calling the `f' argument to areduce1
18:40Bronsakaiyin: say you're reducing a long[], using areduce (aget arr idx) will be inlined and the long will not be unnecessarily boxed
18:41kaiyinok.
18:45kaiyinwhy is let [a# ~a] necessary? https://gist.github.com/kindlychung/cd025ba6b79848cb2168#file-areduce-macro-clj-L5
18:46turbofailthe expression you pass in to the macro for `a' might not be constant
18:46turbofailand may have side-effects
18:46turbofailif it didn't bind it to a variable it would end up re-executing that expression a bunch of times
18:46kaiyinso let [a# ~a] is a kind of snapshot?
18:46turbofailyeah
18:52kaiyinwhat about this then: https://gist.github.com/kindlychung/cd025ba6b79848cb2168#file-ar2-clj
18:52kaiyinwouldn't it be a simplification?
18:53Bronsakaiyin: as soon as you introduce `f` you're introducing boxing of the args
18:54kaiyinok, i see.
19:07chouserNo implementation of method: :put! of protocol: #'clojure.core.async.impl.protocols/WritePort found for class: clojure.core.async.impl.channels.ManyToManyChannel
19:08chouserSurely I'm supposed to be able to >!! on a channel?
19:10chouserugh. reloaded protocols or similar. nevermind. :-P
19:25chouserAm I wrong to want async/keep instead of async/map?
19:29escheriz`When setting up a new website-like-project, do folks usually use Luminus? https://github.com/luminus-framework/luminus Or start from scratch? Or something else?
21:13timvisherdo ns renames work? i.e. `(ns charnock (:require [whitefield :refer [piper] :rename {piper w-piper}]))`?
21:13timvisheri can confirm that the above syntax doesn't work for me right now so i suppose the real question is how do i format that :)
21:13creeseI'm looking for a JSON Schema library that supports draft 4. Is there such a thing?
21:20timvisherwhere is the documentation for `(:refer` in an ns form? i've never seen this before
21:22timvisherit seems that's the way to get renames, but it would also appear to refer in all the other public vars in that ns
21:22gfredericksyou can get renames with require
21:22timvishergfredericks: ooo! tell me tell me :)
21:22gfredericks,(require '[clojure.string :refer :all :rename {join uberjoin}])
21:22clojurebot#error{:cause "denied", :via [{:type java.lang.SecurityException, :message "denied", :at [clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69]}], :trace [[clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69] [clojurebot.sandbox.proxy$java.lang.SecurityManager$Door$f500ea40 checkPropertyAccess nil -1] [java.lang.System getProperty "System.java" 708] [su...
21:23gfrederickswelp
21:23gfredericks&(require '[clojure.string :refer :all :rename {join uberjoin}])
21:23lazybot⇒ nil
21:23gfredericks&split
21:23lazybot⇒ #<string$split clojure.string$split@330ace48>
21:23gfredericks&join
21:23lazybot⇒ #<set$join clojure.set$join@3b7a1bf>
21:23gfredericks&uberjoin
21:23lazybot⇒ #<string$join clojure.string$join@459225a0>
21:23timvishergfredericks: i need it in the ns form
21:23timvisherobviously it works with a call to require
21:23gfredericksyeah so you can do the same thing with require in the ns form
21:23timvisheroh
21:24timvisherweird. let me check again. i thought i did that
21:24gfredericksthe entries in the ns form are basically just calls to the equivalent functions
21:24gfredericksyou can actually call any clojure.core function that way I think
21:25gfredericksit's a classic clojure party trick
21:25timvisheressentially i've got `(:require [compojure.core :refer [ANY context] :rename {routes c-routes}))`
21:25timvisherand that seems to be blowing up
21:25timvishersec
21:26gfredericksyou gotta refer routes too
21:26timvisherah
21:26gfredericksit's a bit redundant
21:28gfredericks,(require '[clojure.walk :rename {+ taco}])
21:28clojurebotnil
21:28gfredericks,+
21:28clojurebot#object[clojure.core$_PLUS_ 0x6c2365aa "clojure.core$_PLUS_@6c2365aa"]
21:28gfredericks,taco
21:28clojurebot#error{:cause "Unable to resolve symbol: taco in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: taco in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6543]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: taco in this context", :at [clojur...
21:28gfrederickswell it was worth a try
21:29timvisher,(ns charnock (:require clojure.string :refer [split] :rename {split s}))
21:29clojurebot#error{:cause "Unsupported option(s) supplied: :rename", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.Exception: Unsupported option(s) supplied: :rename, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.core$throw_if doInvoke "core.clj" 5626]} {:type java.lang.Exception, :message "Unsupported option(s) supplied: :rename", :at [clojure.core$load_libs doInvoke "core.clj" 57...
21:30timvisherhmm... is that the jail doing that? that's not the error i'm seeing
21:30amalloyno, you just have a totally wrong ns form
21:30amalloyneeds []s
21:31gfredericksadd moar square parens
21:31timvisherlol
21:31timvisheri shouldn't be coding...
21:31amalloyarguably you are not
21:32timvisherwait... since when have i not been able to use a list instead of a vector?
21:32timvisheram i thinking of project.clj?
21:32timvisherdoes it have to be a vector in the ns form?
21:33timvisherdidn't tbaldridge post some craziness forever ago when proposals were being made to change the ns form?
21:33timvishergreat scott! it worked!
21:34timvisherseriously, i don't remember ever having tried this before but i thought vectors or lists there didn't matter one bit
21:34timvisherthat's never been a thing?
21:41gfrederickswell the one you tried above didn't use a list either