#clojure logs

2015-05-26

01:44curtmackSo... I'm getting an error that I can't type hint a primite local, but I'm using the (long-array arg) form as recommended, and if I do nothing then I get a reflection warning with *warn-on-reflection* turned on
01:44curtmackam I just SOL or is this a bug of some sort?
01:48curtmackExample with no type-hinting: http://ideone.com/Cajkyx , example with type-hinting: http://ideone.com/0nxeYJ
01:49andyfMy memory isn't perfectly clear on this, but I have a recollection that asset is easier to type hint than the aset-* variants.
01:49andyfs/asset/aset/
01:50amalloyyou can't typehint protocol functions anyway. type hints are for interop
01:51amalloyand you have a ton of needless code in here: (all your record's fields are in scope in method/protocol implementations, so you can just write state instead of (:state self)
01:51andyfAlso try hinting ^longs on old-state when it is bound to a value in the let, before using ager on it.
01:52andyfsigh. s/ager/aget/
01:52curtmackandyf: still doesn't work
01:52amalloyandyf: it shouldn't need any hints at all there, if he just uses state instead of (:state self)
01:52andyfYeah, listen to amalloy. He is probably more awake and has more recent relevant experience with this.
01:52curtmackamalloy: OH, that helps a lot... legitimately did not know that
01:53amalloythe compiler can infer types if you use the fields directly, but if you do a keyword lookup it doesn't know what type it will come up with
01:54curtmackokay yeah that worked, thanks a lot
01:54curtmackthat makes sense
01:58amalloycurtmack: also, your shuffle doesn't look fair
01:58amalloytry it on the two-element deck [0 1] - i predict you will get out [0 1] 100% of the time
01:58amalloyer, [1 0] is what i rpedict you will get
01:59curtmackoh right, good catch
02:00curtmackit's supposed to be mod (inc i)
02:00curtmack0 <= j <= i
02:41curtmackexit
03:31crocketDoes scala interoperate with clojure well and vice versa?
03:32tdammerscurrently my test suite of 3 rather trivial assertions takes about 30 seconds to run (lein test), is there anything I can do to bring this down to something workable?
03:32tdammers(I'm running on a brand new i7 with plenty of RAM, so "throw more hardware at it" is not going to be the solution)
03:39amalloytdammers: the problem is vague enough ("my program is slow") that the only possible answers are "throw more hardware at it" or "write a better program"
03:44TEttingertdammers: clojure does have kinda long startup time, there's several factors at work here and some are pretty solvable
03:44TEttingerone is lein itself
03:45TEttingerif your project is large, lein has to do a lot to get the whole project loaded, and lein itself needs to get up and running
03:46TEttingergrenchman is a rewrite of part of lein in OCaml that can call standard clojure lein and use project.clj, etc. but start up like OCaml (faster)
03:46TEttingerdrip solves the JVM startup time issue
03:47TEttingera JVM needs to load a 32 MB file completely into RAM every time it starts up, and before it has even started the HotSpot JIT compiler
03:47TEttinger(load from disk)
03:47TEttingerDrip does the loading and warming up long before you actually invoke lein
03:48luxbockdoes anyone here use a Clojure REPL as a shell replacement?
03:48TEttingerand keeps a spare JVM warmed up for when you want it
03:48luxbocki.e. have one REPL session running all the time with some handy libraries loaded
03:48TEttingerI think many people do, luxbock
03:49TEttingerI don't, personally, I haven't been too bothered by startup time
03:50luxbockif anyone sees my message, please do share the list of libraries you load :)
03:50luxbockTEttinger: right so the idea would be that this REPL session would be running at all times
03:51luxbockso startup time wouldn't be an issue
03:51TEttingeryah
03:51TEttingerI mean if I need it, I just start up a new one
03:51TEttingerI usually use lazybot or clojurebot for simple repl stuff
03:51TEttingeror my own lazybot
03:52luxbockyou have your own lazybot?
03:52luxbockis it high maintenance?
03:52TEttingernot any more
03:52TEttingerit used to be
03:52luxbockhad to put it down? :(
03:52TEttingerI added a feature that makes it start itself up again if it dies
03:52TEttingerhttp://i.imgur.com/Po3ZsbH.png
03:53TEttingerit hasn't needed maintenance in months
03:58jefelanteoffhand, anyone know an example of an application that stores state relationally in memory and queries it with core logic?
04:13sm0keproblem is you THINK that what you THINK is RELAITY
04:13sm0kesnap out of it
04:13bendlas,(do (declare x) (meta #'x))
04:13clojurebot{:declared true, :line 0, :column 0, :file "NO_SOURCE_PATH", :name x, ...}
04:14bendlas,(do (declare x) ((juxt :namespace :name)(meta #'x)))
04:14clojurebot[nil x]
04:14sm0ke,(do (declare x) (:namespace (meta #'x)))
04:14clojurebotnil
04:14bendlas,(do (declare x) ((juxt :ns :name)(meta #'x)))
04:14clojurebot[#object[clojure.lang.Namespace 0x7fb7a98f "sandbox"] x]
04:14sm0ke,(do (declare x) (:ns (meta #'x)))
04:14clojurebot#object[clojure.lang.Namespace 0x7fb7a98f "sandbox"]
04:14sm0kebendlas: you monsterr
04:14sm0kethanks
04:14sm0ke(inc bendlas)
04:14lazybot⇒ 3
04:15bendlas,(do (declare x) ((juxt (comp #(.getName %) :ns) :name)(meta #'x)))
04:15clojurebot[sandbox x]
04:15bendlas^^
04:17crocketsm0ke, The same could be said about you unless you give me convincing arguments.
04:17crocketMany people don't like working with scala for Scala's complexity
04:17crocketClojure is simple and elegant.
04:18bendlasscala wins out when optimizing for http://xkcd.com/303/
04:19crocketbendlas, The same can be said about C++.
04:20sm0ke,(do (declare x) (ns foo) (def y sandbox/x) (:ns (meta y)))
04:20clojurebotnil
04:20sm0ke,(do (declare x) (ns foo) (def y sandbox/x) (:ns (meta #'y)))
04:20clojurebot#object[clojure.lang.Namespace 0x647c4297 "foo"]
04:20sm0kebendlas: how do i get sandbox instead
04:21bendlascrocket: yep, but C++ also wins in a lot of other categories, like allocation-free code or introducing unintentional remote-management capabilities ^^
04:22sm0keC is the best
04:22crocketC isn't the best.
04:22crocketClojure is one of the best general purpose programming languages.
04:22sm0kecrocket: you will relaize one day how right i was
04:23crocketsm0ke, I know where C is the best and where it is not.
04:23crocketC dominates system programming.
04:23bendlas,(do (def x "x-val") (ns foo) (def y sandbox/x) ((juxt (comp :ns meta) identity) #'y))
04:23clojurebot[#object[clojure.lang.Namespace 0x647c4297 "foo"] #'foo/y]
04:23crocketIn web programming and general programming, C sucks a lot
04:23bendlas,(do (def x "x-val") (ns foo) (def y sandbox/x) ((juxt (comp :ns meta) deref) #'y))
04:23clojurebot[#object[clojure.lang.Namespace 0x647c4297 "foo"] "x-val"]
04:23crocketIn general programming, I tend to use clojure.
04:23bendlaswhat's the problem?
04:24crocketC has weakly static typing, which sucks.
04:24sm0kebendlas: i will show you
04:24sm0ke,(do (declare x) (ns foo) (def y sandbox/x) (str y))
04:24clojurebot"x-val"
04:24bendlasany typing but dependent typing is weak to klingons
04:24sm0ke,(do (declare xx) (ns foo) (def y sandbox/xx) (str y))
04:24clojurebot"Unbound: #'sandbox/xx"
04:24crocketRust as a language beats C and C++.
04:25sm0keso i am trying to get the topmost binding ns
04:26bendlassm0ke: I don't understand, you just declare xx, without defining it, thus it's unbound, but the var object exists in the expected ns
04:26oddcullyrust, paper, scissors
04:28bendlassm0ke: the current ns is ,*ns
04:28bendlaserm ...
04:28bendlas,*ns*
04:28clojurebot#object[clojure.lang.Namespace 0x426e9bbf "sandbox"]
04:28sm0kei want to get the Root ns of a var
04:29sm0ke,(do (declare x) (ns foo) (def y sandbox/x) (:ns (meta (.getRawRoot #'y))))
04:29clojurebotnil
04:29sm0kei fail
04:29sm0ke,(do (declare x) (ns foo) (def y sandbox/x) (.getRawRoot #'y))
04:29clojurebot"x-val"
04:29sm0ke,(do (declare xx) (ns foo) (def y sandbox/xx) (.getRawRoot #'y))
04:29clojurebot#object[clojure.lang.Var$Unbound 0x37d710ef "Unbound: #'sandbox/xx"]
04:29bendlassm0ke: as soon as you get the var root, it's not the var anymore
04:30sm0ke,(do (declare xx) (ns foo) (def y sandbox/xx) (.getNameSpace (.getRawRoot #'y)))
04:30clojurebot#error {\n :cause "No matching field found: getNameSpace for class clojure.lang.Var$Unbound"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: getNameSpace for class clojure.lang.Var$Unbound"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Re...
04:30bendlasvalues don't retain information about their containing var
04:30sm0kethen what is getRawRoot for?
04:31bendlasif you want to get around thread-local binding in a ^:dynamic var
04:31bendlassm0ke: so, mostly an implementation detail
04:33sm0kehttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Var.java#L170
04:33sm0keonly if somehow i could get hold of that `ns`
04:35bendlassm0ke: you can, but not from the contained value. don't be confused by that `clojure.lang.Var$Unbound`, that's debugging info and should not be relied upon
04:36bendlasyou need to get the #'var-object, which can be done at runtime by (resolve 'var-object)
04:36bendlasthen get the ns from meta
04:40sm0kei think i got it
04:40sm0ke,(do (declare xx) (ns foo) (def y sandbox/xx) (.. (.getRawRoot #'y) v ns))
04:40clojurebot#object[clojure.lang.Namespace 0x1d37da3a "sandbox"]
04:40sm0keenjoy!! :D
04:41sm0kesurely not to be relied upon though
04:42bendlaswell, yeah
04:47bendlas,(do (declare triple-x) (.. triple-x v ns))
04:47clojurebot#object[clojure.lang.Namespace 0x1d37da3a "sandbox"]
04:48sm0ke,(do (declare xx) (ns foo) (def y sandbox/xx) (.. #'y v ns))
04:48clojurebot#error {\n :cause "No matching field found: v for class clojure.lang.Var"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: v for class clojure.lang.Var"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceMember "Ref...
04:48sm0ke,(do (declare xx) (ns foo) (def y sandbox/xx) (.. y v ns))
04:48clojurebot#object[clojure.lang.Namespace 0x1d37da3a "sandbox"]
04:48sm0keweird
04:49sm0keso getRawRoot is not required at all?
04:49bendlasno, why should it?
04:50bendlasclojure.lang.Var$Unbound is the class of a value, that represents debugging-info, with which `declare d vars are initialized
04:51bendlas.getRawRoot is implicit to any (non-dynamic) var reference
04:52bendlasVar$Unbound is a relatively recent addition, some time ago, references to just-declared vars threw exceptions
04:54sm0kesorry i dont understand
04:54sm0kebut i am guessing `v` would always point to the root variable
05:05bendlas-mobilesm0ke, no
05:05bendlas-mobile,(do (def triple-x "foo") (.. triple-x v ns))
05:05clojurebot#error {\n :cause "No matching field found: v for class java.lang.String"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: v for class java.lang.String"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceMember "Ref...
05:05bendlas-mobilethere is no "root variable"
05:06bendlas-mobileEach variable has a root slot
05:10zotwhat is the idiomatic way to convert [:a :b :c] -> {:a (f :a), :b (f :b), :c (f :c)}?
05:10bendlas-mobileThat slot just holds the current value of the var
05:11Bronsazot zipmap+map
05:11justin_smith,(into {} (map (juxt identity name) [:a :b :c])
05:11clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
05:11justin_smith,(into {} (map (juxt identity name) [:a :b :c]))
05:11clojurebot{:a "a", :b "b", :c "c"}
05:12tdammersTEttinger: thanks for the pointers, I'll look into it
05:12Bronsa,(let [v [:a :b :c] f name] (zipmap v (map f v))
05:12clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
05:12Bronsa,(let [v [:a :b :c] f name] (zipmap v (map f v)))
05:12clojurebot{:a "a", :b "b", :c "c"}
05:12zottnx Bronsa and justin_smith :) perhaps canonical is too strong a word :)
05:22mmeixjust reading about transducers ... is this something, a beginner should learn alongside the basics, or afterwards?
05:23bensummeix, afterwards, when you are comfortable transforming collections
05:23mmeix(being fluent enough with map filter reduce & co.)
05:25mmeixwould it change code radically, or can I rework later, without writing much from scratch?
05:28m1dnight_Guys, I'm trying to resolve the value of a var at runtime by its string name but I cant seem to succeed
05:28m1dnight_I always get #'user/myvar
05:28m1dnight_not the actual value
05:28m1dnight_(def myvar 1) (ns-resolve *ns* (symbol "myvar")) is what im doing now
05:35m1dnight_get-var!
05:36justin_smith,@(resolve '+)
05:36clojurebot#object[clojure.core$_PLUS_ 0x5f47e56f "clojure.core$_PLUS_@5f47e56f"]
05:36justin_smithm1dnight_: all you need is to deref
05:36bendlas-mobileBeware, *ns* is tricky
05:37justin_smithm1dnight_: also, for things you use as functions, you don't need to deref
05:37bendlas-mobileOnly properly works in top level
05:37justin_smith,(#'+ 2 2)
05:37clojurebot4
05:38bendlas-mobileOr during compile time
05:41m1dnight_ah like that
05:41m1dnight_okay I get it
05:41m1dnight_thanks guys
08:47dysfunhow cheap are core.async channels? i'm wondering if you're better off passing a message with a correlation id or just creating a new one-use channel for a response
08:48dysfunwell, not one-use, but per-id
09:32crocketDoes http://dpaste.com/2PYB0ZD leak a channel?
09:33crocketI see no point at which the channel is destroyed.
09:33crocketor closed
09:35auxcharI wonder if you need a timeout, maybe.
09:36justin_smithcrocket: if you write a nil to the channel it will be closed and the go loop reading it will stop, iirc
09:37justin_smithalso, consider (repeatedly num-quotes #(put! c (rand-quote)))
09:37justin_smithfor the last line
09:38crocketjustin_smith, That function was for side effect.
09:38justin_smithcrocket: oh, sorry, I forgot repeatedly was lazy
09:39justin_smith,(dorun (repeatedly num-quotes #(put! c (rand-quote))))
09:39justin_smitherr
09:39clojurebot#error {\n :cause "Unable to resolve symbol: num-quotes in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: num-quotes in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: num...
09:59auxcharYou'll have to excuse me, I'm new at this, but holy cow, you can put docstrings on any var!? That's awesome.
09:59ToxicFrogYep.
10:00auxcharWell, those magic number vars just got a whole lot more useful.
10:01crocketHow does a go process even exit on http://dpaste.com/2PYB0ZD ?
10:01crocketIt is on an infinite loop.
10:01crocketDoes it mean http://dpaste.com/2PYB0ZD leaks a go process?
10:02justin_smithcrocket: you should check if the channel is closed (and close the channel)
10:02justin_smithalso, you don't need to start a go in order to send a message, just use put! which is async and works outside a go block
10:03crocketjustin_smith, If you read it again, I called put! outside a go block.
10:03justin_smithso if you really want the dotimes with unused n (dotimes [_ num-quotes] (put! c (random-quote)))
10:03justin_smithyou don't
10:03crocketLook again
10:03justin_smithI read it again
10:03crocketoops
10:04justin_smithalso, it's good to use _ instead of n
10:04justin_smiththat indicates you aren't using the binding
10:04crocket,(doc >!)
10:04clojurebotTitim gan éirí ort.
10:04crocketWhut
10:04crocket,(doc put!)
10:04clojurebotCool story bro.
10:04crocketWhut
10:04justin_smith,(require 'clojure.core.async)
10:04clojurebot#error {\n :cause "Could not locate clojure/core/async__init.class or clojure/core/async.clj on classpath."\n :via\n [{:type java.io.FileNotFoundException\n :message "Could not locate clojure/core/async__init.class or clojure/core/async.clj on classpath."\n :at [clojure.lang.RT load "RT.java" 449]}]\n :trace\n [[clojure.lang.RT load "RT.java" 449]\n [clojure.lang.RT load "RT.java" 412]\n [cl...
10:04oddcullyits not in clojure.core
10:04crocketputs a val into port. nil values are not allowed. Must be called
10:04crocket inside a (go ...) block. Will park if no buffer space is available.
10:04crocket Returns true unless port is already closed.
10:04oddcullyhence the bot insulting you
10:05crocketThe documentation of >! tells me to use >! inside a go block.
10:05crocketFair deal
10:05crocketjustin_smith, ^^
10:05justin_smiththat's why I said use put!
10:06justin_smith"Asynchronously puts a val into port..."
10:06crocketjustin_smith, ok
10:06crocketput! is not the same thing as >!
10:07justin_smithright
10:07justin_smithput! is the one to use if all you are doing is putting a value onto a channel, no need to make a go block for that
10:08credulousHey, folks: etiquette question. I asked a question in #clojure-beginners because it's embarrassingly basic. That channel seems a bit quiet though? Should I just be more patient or is that channel dead?
10:09crocketjustin_smith, Can you have a look at http://dpaste.com/3CS2N3H and tell me how to close the go block?
10:11crocketIf while-let existed, it would be easy to do so.
10:16tcrayford____credulous: think it's up to you. Certainly there are folk who hang around in there a bunch. It's probably quiet because of time of day
10:18crocketIs it simple to interface JavaFX in clojure?
10:18credulousThanks tcrayford____, I'll keep it there then
10:18tcrayford____credulous: if it's more urgent I'd typically ask in here
10:19tcrayford____or rn, feel free to ask me directly :)
10:20credulousNot urgent, just rookie. Beginner at both Clojure and Emacs. Trying to load "buddy" library in the repl, can't seem to do it.
10:21credulousI've run "lein deps" for the project and it works fine
10:21credulousbut:
10:21creduloususer> (require 'buddy)
10:21credulousFileNotFoundException Could not locate buddy__init.class or buddy.clj on classpath: clojure.lang.RT.load (RT.java:443)
10:21sandbagscrocket: there is a project for that
10:21credulousHappens no matter what ns I'm in
10:22crocketsandbags, Actually I found two projects so far.
10:22crockethttps://bitbucket.org/zilti/clojurefx and https://github.com/aaronc/fx-clj
10:22sandbagscrocket: i was going to say actually there should be 3
10:22sandbagsthe one i looked at is by Tim.... i forget
10:22tcrayford____credulous: looks like that namespace doesn't exist, I guess?
10:22sandbagskind of React for JavaFX
10:23sandbagsfn-fx
10:23sandbagshttps://github.com/halgari/fn-fx
10:23tcrayford____credulous: which bit of buddy were you looking to use/were you following a tutorial?
10:23credulousThat's what it looks like to me... but I get the same error for (require 'buddy.core) and (require 'buddy.core.hash)
10:23credulousLoosely following a tutorial, but wanted to experiment with the sha2 and sha3 hashing functions
10:24sandbagscrocket: i liked the fn-fx concept but I am not sufficiently versed in JavaFX to use it and I was afraid that Tim, having so many other commitments, wouldn't continue developing it
10:24tcrayford____credulous: wanna link the tutorial then?
10:24credulousThe code that I "require" buddy in compiles fine, but I don't know if that means anything
10:24schmircrocket: I decided to use java interop with some small helper functions in order to use javafx..it's easy enough
10:24tcrayford____credulous: looks like `(require 'buddy.core.hash)` should work
10:25credulousurk
10:25credulousPasted that in from the git page just as you were typing
10:25credulousRubber duck moment.
10:25tcrayford____np
10:29crocketschmir, You juse use plain JavaFX on clojure?
10:29crocketPOJO
10:29schmircrocket: yes, with some small helper functions.
10:31crocketschmir, Can you show me the codebase?
10:31schmircrocket: no, sorry. it's not open source
10:32crocketDamn you
10:35maxpn'lein repl' in project directory uses different timezone offset than 'lein repl' in home directory. How it is possible?
10:36maxpnit is with clj-time
10:36gfredericks that's fascinating
10:37gfredericksI think `lein repl` in the homedir creates a repl inside the lein jvm, but no idea if/how that's related
10:37maxpnit could be with old timezone info file
10:38maxpnwhat is the difference betweein 'lein repl' with project.clj and whihout?
10:39maxpnwhere it could find old incorrect zonefile?
10:43arav93Are there any Indians here?
10:44arav93I just wanted to know if there are clojure conferences in India
10:44arav93*there are any
11:00sdegutisHello.
11:14wasamasahey
11:16sdegutiswasamasa: you're into Clojure now?
11:16wasamasasdegutis: well, yeah
11:16sdegutiswasamasa: well at least you got a good start on Emacs first
11:17wasamasasdegutis: not like that helps me understanding how to start hacking on something less toy-like than what I've written so far
11:17sdegutiswasamasa: I haven't seen Clojure that doesn't look toy-like from a distance; it's part of the language's charm
11:17sdegutisThe language doesn't take itself too seriously like Java does.
11:18wasamasaI mean, the project
11:18wasamasasure, it's nice that someone figured out how to make the problem of organizing a complex application sound less enterprisey and more functional
11:18wasamasayes, I'm refering to https://github.com/stuartsierra/component
11:19sdegutisCan anyone see the pattern I'm missing here? I've got two functions which take a state and a param, and return a new state and a new object. And I want to compose them naturally, so that I can create a wrapper function which calls them both, and returns the second new state, along with both newly created objects.
11:20sdegutisHere's the code: https://gist.github.com/sdegutis/20a3ba5f4e1cb826de04
11:20sdegutiswasamasa: Oh. I've never used Component. Heard a lot about it though. Then again I heard a lot about Pedastal back in the day. I usually wait about 2 years to see how well a library plays out before using it.
11:20sdegutiswasamasa: That said, Component does look handy.
11:21wasamasaoh, sure
11:21sdegutisCrap. My question got lost amidst a separate conversation.
11:21wasamasabut what if I don't want to stub or mock and just explore how something works
11:21sdegutisWelp.
11:21wasamasain a REPL
11:21sdegutiswasamasa: lein repl
11:22sdegutislein pretty much solved every tooling problem in Clojure
11:22sdegutislein test, lein repl, lein uberjar, etc
11:22sdegutisoh, and lein run
11:22wasamasasdegutis: it's more about, how the hell do I access the database used by the utility functions involving it built around that model
11:22wasamasasdegutis: to make use of them
11:22sdegutisIt's like somehow they *knew* what we needed to get done!
11:23sdegutiswasamasa: huh?
11:24wasamasasdegutis: it is somewhere, I know
11:26wasamasasdegutis: look at the example
11:28wasamasasdegutis: how would you test any of the functions making up the behaviour of the database component?
11:29sandbagswasamasa: maybe look at ring.mock.request and see if you can cook up something equivalent for your db?
11:30wasamasasandbags: I want to make use of the db as used by the web application
11:30wasamasasandbags: this must surely be possible, no
11:30justin_smithwasamasa: this is what I use stuartsierra's component lib for
11:30sandbagswasamasa: i'm not sure what problem you are having then
11:31justin_smithwasamasa: each component is a stateful resource, that can be substituted at testing time, or initialized individually for repl hacking
11:42crocketWooHoo
11:43justin_smithcrocket: so you end up with something like (go-loop [] (if-let [input (<! c)] ... (recur)) (println "loop exit"))) or whatever
11:44justin_smiththat's bad paren nesting, but I hope you get the idea
11:44wasamasaor I just use the var it was established with :P
11:44justin_smithwasamasa: I mean in a unit test you can instantiate a component on its own
11:44justin_smithwithout needing to create the whole nested system
11:45justin_smithso each component can have isolated tests
11:46justin_smithwasamasa: not that this can't be done in normal code, but the component system makes the discipline of isolating functionality much more natural to maintain
11:48wasamasajustin_smith: I'll keep that in mind when it comes to writing more tests
11:48wasamasajustin_smith: so far the codebase got asserts here and there
11:48crocketWhat is transducer?
11:48justin_smithcrocket: it separetes the logic of computation from the containers that the results would be put into
11:49justin_smithcrocket: for example, usually if you use map or filter, this means creating a lazy seq, but with the transducer version, you pick where the results go directly
11:49crocketok
11:51justin_smithcrocket: for example, if you have nested map calls, you create as many lazy-seqs as you have calls to map. But composed map transducers compose directly without making intermediate collections.
12:10mmeix(just watching Stuart Sierras talk on Components - this is beautiful stuff indeed ...)
12:12prosei used instaparse to make a language that has syntax like IO but compiles to CLojure and ClojureScript
12:12prosehttps://github.com/aaron-lebo/prose
15:57m1dnight_i just discovered clojure monads. Now I recall so many moments I thought "well, i wish I had monads now"
16:01sorbo_I was so mad when I found them for Go (https://github.com/SimonRichardson/wishful) and they weren't called gonads
16:02kwladykaOk i read about Enlive, but i think it is not "keep it simple", but it is good separate frontend people from coders.... still not sure it is good
16:02m1dnight_hahaha :) They missed out there indeed, sorbo_
16:06sverikwladyka: I'd use it for larger projects when generating a lot on the server side with some nifty html markup
16:21TimMcm1dnight_: A word of warning -- monads take away your ability to use tools.trace effectively.
16:21TimMcI just ran into that recently.
16:22TimMcErr... I guess just things like the error-state monad, come to think of it.
16:23justin_smith((juxt inc dec) sorbo_) ; for puns
16:23justin_smithamazingly that command works as expected, despite not being implemented
16:23m1dnight_:D :D :D
16:23m1dnight_TimMc: I actually have never used tools.trace.
16:23sorbo_w00t
16:24m1dnight_So many things I have to learn :<
16:24m1dnight_Im writing a thesis, I have a valid excuse!
16:28xemdetiam1dnight_, that only buys you so much time!
16:30m1dnight_deadline is in 2 weeks :(
16:30m1dnight_implementation is barely done and I have to write 2 chapters and find a good evaluation program
16:30m1dnight_and here i am trying to update cider in emacs for no good reason :p :p :p
16:30justin_smith(inc yaks)
16:30lazybot⇒ 1
16:34amalloyspeaking of clojure monads, i see http://www.reddit.com/r/Clojure/comments/37bzut/how_can_i_make_this_functions_internals_more/ and i'm so tempted to say "gosh, you just want to use the `State DB` monad" but i know it is not helpful at all
17:11irctc,(apply and true true [true true true])
17:11clojurebot#error {\n :cause "Can't take value of a macro: #'clojure.core/and"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Can't take value of a macro: #'clojure....
17:12irctcWhat's the standard way of getting around calling apply with a macro like 'and' ?
17:12amalloy&(doc every?)
17:12lazybot⇒ "([pred coll]); Returns true if (pred x) is logical true for every x in coll, else false."
17:17irctcamalloy: ,(every? identity [:asdf #{:a} 'clojure])
17:22gfredericks,(every? identity [:asdf #{:a} 'clojure])
17:22clojurebottrue
17:22gfredericksit kind of annoys me that and can't be a function
17:24eindoofushi, does clojure do type checking at compile time?
17:26TimMcgfredericks: should be an and* and or*
17:27arohnereindoofus: no. There's core.typed (optional static typing), but I'd recommend getting more familiar w/ the language first before using it
17:28wasamasaeindoofus: you usually get the errors once the compiled code is evaluated
17:29eindoofusarohner, if i'm trying to do some more dynamic style programming like python using the jvm what language would you recommend?
17:29gfredericksTimMc: I'm not entirely opposed to that
17:29arohnereindoofus: clojure :-)
17:29eindoofusi'm trying to find something flexible for to aid in the creation of dummy data
17:29arohnergfredericks: TimMc: how would they work? and & or promise not not eval arguments. clojure fns are strictly evaluated
17:30TimMcarohner: and* would have the same value semantics as and, but with no delayed eval
17:30TimMc(def and* #(and % %2))
17:31TimMcarohner: This would be nice for (reduce and* ...)
17:31wasamasaaren't there equivalents to some/any and all?
17:31wasamasaas known from scheme and common lisp
17:32ionthas_Is there any implementation of mapv with parallelism? (map has pmap). I couldn't find pmap...
17:32eindoofusarohner, what worries me is that clojure appears to be more of a functional language. i like the ease of dynamic languages
17:32ionthas_(I meant pmapv)
17:32eindoofusbut still need the jvm
17:32wasamasaeindoofus: you're in #clojure, do you seriously expect anyone to advocate anything else
17:33eindoofuswhy not? we're all techies. would expect better answers here than #java
17:33wasamasa...
17:33eindoofusit's just another tool
17:33wasamasaespecially considering that they've tasted the benefits, such as writing more concise and immutable code with less error potential
17:33ronh-eindoofus if you just want python for java you know where to find jython
17:35gfrederickseindoofus: clojure is both functional and dynamic
17:35wasamasa"dynamic" makes little sense as classification anyways
17:36wasamasaI'm pretty sure it's just been coined for marketing purposes (because who wouldn't want to sound "dynamic")
17:36gfredericksI interpret it to refer to being able to easily redefine things; basically everything vars are all about
17:36wasamasaso, not php :D
17:37eindoofusthe only functional language i've seen is javascript and it's warped my mind. not sure what functional means anymore
17:37wasamasatrololol
17:38eindoofusthere is definitely a large difference between java, python, and javascript i would say
17:38wasamasathat is about as meaningful of a statement as saying the same about lentils, potatoes and pasta
17:40wasamasameh, why must programming language discussions be so boring
17:41amalloyTimMc: why would you want to encourage (reduce and* ...)?
17:41gfredericksamalloy: what's the alternative?
17:41amalloyevery?. that's what it's for
17:42gfrederickswell they aren't strictly the same
17:42gfredericksand in any case
17:42amalloy(partial every? identity) is (partial reduce and*), except that it's smart enough to short circuit
17:42gfredericksand* is probably useful in other contects too
17:42gfrederickscontexts
17:42amalloygfredericks: (map and*)? that's fair enough
17:42gfredericksyeah that kind of thing
17:42gfredericksgotta grep a bunch of codebases for #(and %1 %2) to find examples
17:43gfredericksI agree the reduce example is bad for its long-circuiting
17:43amalloyi can get behind that, but when people encourage (reduce and*) in a non-lazy language i have to disagree
17:43functorThis is pretty hard to search, but is there an "and" in clojure that is not a macro? or is the only option to wrap it in a lambda?
17:43gfredericksoh here's an example right here
17:43gfredericksfunctor: what are you going to use it for?
17:44functorSince the ESP is on today, exactly what amalloy is showing: (reduce and [true true true...])
17:45arohnergfredericks: I like the term long-circuiting :-)
17:45functorand* doesn't seem to exist.. where can i grab it from?
17:46amalloyfunctor: the point of the discussion we were just having before you asked that question is that (reduce and* xs) is a terrible thing to do
17:46amalloybecause the function every? exists, and is much better for that
17:47functorWell then. :/
17:47functorso.. every? then?
17:47gfredericksfunctor: better because reduce wouldn't short-ciruit
17:47gfredericks,(every? identity (repeat nil))
17:47clojurebotfalse
17:48gfredericks,(reduce #(and %1 %2) (repeat nil))
17:48clojurebotExecution Timed Out
17:48functorAh! identity, that's what I was missing.
17:48wasamasanice
17:48lvhIs there a merge-with where the fn takes both k and v, or do I do (into (empty m) (map f m))?
17:48functoramalloy, gfredericks thank you
17:48lvherr, I guess that doesn't really do it either; I mean reduce ;)
17:49wasamasafunctor: identity is overall pretty useful if you wish to preserve the argument as is
17:50TimMcamalloy: Yeah, I think map is the case I was thinking of.
17:51functorwasamasa: yea, old me couldn't find a use for it, functional me is starting to get it though :)
17:58TimMcamalloy: No, that's not right. (every? identity ...) doesn't yield the final value, it yields true.
17:58justin_smith,(every? identity [:a :b :c])
17:58clojurebottrue
17:58amalloythat's fine, TimMc. nobody who wants to reduce and over a list cares about the exact value, just its truthiness
17:59TimMcIf you say so.
18:01TimMcI'm not willing to make that generalization.
18:02bensuwhen using clojure.java.shell should I be able to access environment variables?
18:02justin_smithbensu: the ones your jvm started with at least
18:03justin_smithbensu: try running "env"
18:04bensujustin_smith, I tried printenv and nothing happened. I'm running this through lein
18:04justin_smith(sh/sh "env") => :exit 0, :out "TERM_PROGRAM=iTerm.app\nTERM=xterm-256color\nSHELL=/bin/bash\nT..."}
18:04justin_smithmissing a { in my pseudo-paste up there, but I definitely see results
18:05justin_smithoh, env is an actual program
18:05justin_smithprintenv is a shell builtin, to run it you need to start a shell
18:05justin_smithdespite the name, clojure.java.shell/sh does not spawn a shell unless the thing you ask it to run is a shell
18:05bensujustin_smith, thanks, I'll try env
18:06justin_smithoh wait... printenv works here too
18:06justin_smithso maybe you have some other issue
18:06justin_smiths/maybe//
18:07TimMcjustin_smith: It only spawns a sh. :-)
18:09danielcomptoncfleming: current status: trying to become the most unreasonably picky Cursive user - https://github.com/cursiveclojure/cursive/issues/904
18:10justin_smithTimMc: (println (:out (sh/sh "pstree"))) shows the pstree as a direct child of the jvm
18:10justin_smithno sh
18:10bensujustin_smith, thanks, printenv is also empty. It's probably something related to lein since I'm working on a plugin
18:11justin_smithfascinating
18:11justin_smithI assume you mean env is also empty
18:11amalloybensu: what about (System/getenv)?
18:13bensuamalloy, that works!
18:13amalloystrange that that's populated but sh doesn't see any of it
18:14justin_smithcould be that lein is frobbing the environment in a way that does not push it to child processes?
18:15justin_smithlike it's explicitly setting the env, but not exporting?
18:16justin_smithbensu: there is an :env key to shell/sh you can use to explicitly export an environment
18:16justin_smithor create one!
18:17TimMcjustin_smith: Sorry, bad joke.
18:17justin_smithoh, I didn't get it at all
18:18bensujustin_smith, I was trying to avoid managing the environment myself but I guess I have no choice.
18:18bensuamalloy, justin_smith thanks for the help. I'll continue tomorrow.
18:18justin_smithbensu: :env (System/getenv) as trailing args?
18:18TimMc(c.j.shell is in fact capable of spawning shells, but the var you're calling is sh, which is obviously a "partial shell" :-P)
18:18justin_smithahh
18:19justin_smithmy mix up is that /bin/sh exists, and a common NEWB mistake is to expect it to be bash
18:19justin_smithso the semantics of that joke went *WHOOSH* for me
18:21amalloyjustin_smith: you have left me wondering what NEWB is an acronym for
18:21justin_smithhah
18:24TimMcNot Even Writing BASIC
18:26crocketDoes clojure have devices that make it simple to write large codebases?
18:26crocketHaskell has rich typing system that makes it simple, and I heard clojure had other devices to make it simple.
18:29amalloykeyboards, monitors. pretty solid devices for writing large codebases
18:30blkcata keyboard really is exceptionally helpful
18:30crocketI was talking about conceptual devices in clojure.
18:31crocketcontrivances
18:32xemdetiait still is a poorly defined question, what hurt points do you have in your large codebases?
18:32arohnerrelevant xkcd: http://xkcd.com/378/
18:34crocketxemdetia, I wrote quite a few modules in node.js
18:34clojurebotCool story bro.
18:34crocketNode.js doesn't help you organize code.
18:35crocketThat's why I abandoned node.js
18:35xemdetialike.. how? do they not have namespaces? do you not like javascript anymore? do you like geese that fly in v's?
18:36crocketnode.js doesn't have namespaces.
18:36crocketIt has a workaround called require.
18:37xemdetiaok, clojure has namespaces. does that help your question?
18:37crocketI think there would be more.
18:42bensucrocket, watch this http://www.infoq.com/presentations/Simple-Made-Easy
18:43crocketbensu, I did a while ago.
18:44bensucrocket, well, that is what Clojure has to offer in terms of making complex problems more tractable. Conceptual tools that help your code be modular and composable
18:49zerokarmaleftcrocket: the component library is gaining a lot of traction in real-world, large codebases (for some definition of large), and there's plenty of blog posts and conf talks about it
18:50zerokarmaleftthough you can get a lot done with just pure functions and clojure's reference types
18:51danielcomptoncrocket: Clojure often needs 3-10x less code than in other languages, so codebases don't get as large for equivalent functionality
19:30boitumelophetlawhats up fellas
19:35kmaru_p00pshad a question re: http://stackoverflow.com/questions/1147975/in-clojure-when-should-i-use-a-vector-over-a-list-and-the-other-way-around
19:35kmaru_p00psa question Raynes had asked
19:36kmaru_p00psI get the impression that lists should be used rarely
19:36kmaru_p00psso, why is it that map, filter and reduce return lists
19:36kmaru_p00psand not vectors?
19:37weavejesterkmaru_p00ps: Seqs are fine for sequential data.
19:37weavejesterThey just don't provide random lookup.
19:38weavejesterThey can also be lazy
19:39amalloykmaru_p00ps: they don't actually return lists, they return sequences that are printed the same as lists
19:39kmaru_p00psyou mean seqa can be lazy?
19:39kmaru_p00psok
19:40kmaru_p00psoh..ok
19:40kmaru_p00psweavejester: reading up on this now -http://stackoverflow.com/questions/22416387/differences-between-a-seq-and-a-list
19:42weavejesterA list is a seq, but not all seqs are lists :)
19:42kmaru_p00psamalloy and weavejester: so, why does clojure prefer seqs over list or vector?
19:43amalloykmaru_p00ps: because you can't fit a list or a vector of every positive integer in memory at once
19:43weavejesterThey're lazy, and they're fast to construct
19:43kmaru_p00psamalloy or weavejester: thanks..that explains things.
19:47weavejesterHm, yellerapp keep releasing libraries with single-segment namespaces.
20:01amalloyweavejester: it's hard to think of a way to split up yeller-clojure-client into multiple words. it's indivisible
20:03weavejesteramalloy: Well, sure, but it's more that single-segment namespaces have edge-conditions associated with them, since they're compiled as packageless Java classes.
20:03amalloyweavejester: i can't tell if you've somehow missed the irony of my claim that their three-word phrase can't be split up into words
20:03weavejesteramalloy: Oh! Hah! Yes, I did.
20:04weavejesteramalloy: It's late here :)
20:05gfrederickscom.yellerapp.whatever
20:43sdegutisHi. I'm new to Clokire and Functional idioms. What is best practice for testing functions that use (shuffle) without side effects?
20:43sdegutis*Clojure
20:46sdegutisAny help is appreciated? Thanks?
20:47amalloy(let [xs (range 52), shuffled-xs (shuffle xs)] (assert (or (not= xs shuffled-xs) (= xs shuffled-xs)))) ;; rare edge case, but shuffling might leave the deck the same
21:47cflemingDo let blocks or do blocks in general propagate their tag metadata from the last (result) form?
21:48cflemingThreading forms do but that's because of how the macro is expanded.
21:49cflemingActually, thinking it over my question isn't so much about the tag metadata itself as the compiler type inference, I guess.
21:49amalloycfleming: they don't propagate the tag metadata itself, which is kinda a weird thing to do and probably not what you meant
21:49amalloyyes. the compiler does infer types through let/do
21:50cflemingamalloy: Thanks.
21:50sdegutisamalloy: sorry I mean I want to test that my function randomizes several properties
21:50amalloyyou can sorta test it pretty easily, right? (set! *warn-on-reflection* true) (.length (let [x "test"] x))
21:50sdegutisshould i generally just create a Function that does the thing with a given, and then a separate function that calls it with shuffle?
21:50amalloycfleming: and indeed this does not cause a reflection warning
21:51cflemingamalloy: Yep, was just testing that exact case over here.
21:53cflemingLooks like try does not infer types
21:53amalloycfleming: because there are multiple return branches
21:54amalloy(try 1 (catch Exception e :fail))
21:54cflemingamalloy: Yep, makes sense.
21:54amalloymaybe it could be smart enough to collapse them together if it can find a LCA for all the possible return paths
21:55cflemingamalloy: Interestingly if also seems to infer: (.length (if true "true" "false"))
21:55cflemingamalloy: Although only if the two branches are the same type: (.length (if true "true" 0)) warns
21:56amalloyand it doesn't do that if you return the same types from a try/catch?
21:56cfleming(.length (try "test" (finally "finally"))) warns
21:57cfleming(.length (try "test" (catch Exception w "finally"))) also warns
21:57amalloysad
22:02hiredmantry/catch/finally in an expression positions is hoisted at as a fn by the compilter
22:02hiredmancompiler
22:03amalloyoh, right. hiredman: i never quite understood why that is. do you know?
22:04hiredmanhttp://dev.clojure.org/jira/browse/CLJ-1422 http://dev.clojure.org/jira/browse/CLJ-701
22:04hiredmanbecause it is way easier to hoist them out and treat the method/fn call as an expression then to treat the byte code for try/catch as an expression
22:05hiredman(same for loops)
22:08crocketHell guys
22:08cfleminghiredman: That is what I call a tricky jira
22:09matthavenerinteresting, so that's why try/catch/finally doesn't play well with core.async ?
22:09hiredmanthe relationship between the two tickets?
22:09cflemingNo, the loop problem in general
22:09cflemingThat's pretty subtle
22:16cflemingHow does the inference for recur work?
22:16cflemingI guess loop infers the type of its last expression, as with let
22:16cflemingBut what is the type of refer inferred as?
22:16cflemings/refer/recur/
22:19hiredmanit infers as a custom type, and the inferrence logic for if has a special case to pick the type of the other branch of the if one branch is that recur type
22:21cfleminghiredman: So (loop [i 0] (if (< i n) (recur (inc i)) i)) will infer long, because the other if branch has type long?
22:22cfleminghiredman: It's a degenerate case, but what about (loop [i 0] (recur (inc i)))? Does that infer nil because the recur doesn't appear inside an if?
22:23hiredmancfleming: it doesn't really matter
22:23hiredmanthe loop is infinite, so there is no return value, so what the compiler inferes doesn't matter
22:25cfleminghiredman: Fair enough. So recur searches for its nearest enclosing if and then picks the type of the other branch?
22:25hiredmanwell, recur doesn't
22:25cflemingRight, the compiler does
22:25hiredmanrecur reports its return type as a special marker type
22:26hiredmanif expressions, when asked for their type, do some logic examining the types of the branches, which special case that marker type
22:27cflemingOk, that makes sense. Thanks, that's really interesting.
22:29hiredmanit would be interesting to see the compiler do HM/algorithm-w inference, just to contrast with "Rich's Algorithm"
22:30hiredmandoubly interesting because hm is generally applied to inference and checking, but clojure only case about inference
22:31hiredmanI think Bronsa had some patches for clj-701 in his cinc work
22:41cflemingYeah, Clojure's algorithm is really only type propagation
22:54sdegutisI have come up with this plan:
22:55sdegutisWrite a function that returns a list of things and the shuffle function. Then write another function which calls that function and performs the given function on the list it also gives back.
22:55sdegutisI can test this with the principle of indirection.
22:56sdegutisI can test that A returns [shuffle, [1,2,3]], and that (B x y) just returns (apply x y).
22:57sdegutisThis gives me indirect assurance that the list is going to be shuffled. Right?
22:58ddellacostafeeling a bit dense here--using Prismatic's schema, how does one go about creating a schema using a predicate function? That is, I simply want to validate an argument to a function by whether or not it satisfies a predicate. I thought I could use s/conditional but that seems to require a schema or schemas itself.
22:59ddellacostaer, and to answer the question myself, looks like I can use schema.core/pred. Nevermind.
23:13gfrederickssdegutis: is using clojure.core/shuffle one of your requirements? like you couldn't switch to a more functional shuffle function?
23:19andyfsdegutis: I'm being dense here. You have a function "uses-shuffle" that internally uses clojure.core/shuffle in its implementation, in a way that affects its return value, and you want to know a good way to write unit tests of uses-shuffle?
23:20andyfWhere I am using 'function' there not in the pure function sense.
23:24andyfgfredericks: You should have that cough looked at. May need professional help
23:27gfredericksandyf: I'll make a jira ticket to remind myself
23:28andyfSteps to reproduce could get disgusting
23:30sdegutisgfredericks: not a hard requirement
23:30sdegutisandyf: I just want to verify that a function is shuffling things it gives me back
23:31andyfsdegutis: Could you call it twice, and check that the return sequences contain the same set of values?
23:32sdegutisandyf: It actually has several levels of complexity in this functino. Even if the top level is shuffled, there's no way of determining their equality at all.
23:33andyfor sort the 2 sequences and check they are equal (same thing, more specific method)
23:34andyfCertainly it would get more challenging if it is more complex than simply shuffling an argument, or shuffling once just before returning.
23:34andyfMaking intermediate computed values observable in the test harness, and checking those intermediate values, could make it easier. That may simply be another way of saying what you were suggesting earlier.