#clojure logs

2015-10-05

00:03Ilienamra: Regarding the "right way" to use riemann, should I create a new project with lein and try to add riemann as a dependency?
00:04IlieWill my lean repl :connect localhost:5557 work?
00:05justin_smithIlie: I mentioned requiring it from your own project because that's normally how we use clojure libs, but it could be reimann has it's own conventions
00:05namraIlie: do you just want to use riemann in production or do you want to add you custom functionality to riemann? or is there some feature in the master branch that isn't within one of the prebuild uberjar releases?
00:06namraeven if you have some custom stuff like with your email, there's really no need to fiddle with the riemann source
00:06IlieI want to use riemann in production, I'm presenting my POC tomorrow to management, any help is more than appreciated
00:06IlieOk, so I should create a new lein project and try to add riemann in the dependencies list?
00:07namrathen i'd recommend you to just download a prebuild uberjar instead of wrestling around with leiningen
00:08namraand then you can take your custom functions you have in function.clj put that in the same directory as riemann.config and add (include "functions.clj") to the top of riemann.config
00:08namrathat's really it. no need for leiningen.
00:09namrathere are even binary packages for the major linux distributions
00:10IlieOk, thank you again for the help guys
00:18IlieI'm using (require 'riemann.seiso) and it works, I moved seiso.clj to src/riemann/seiso.clj, thank you again for your help
01:10zematisIs there a simple function to remove members of one collection from another collection, but only in proportion to the amount of them in each collection?
01:10zematise.g:
01:10zematis(remfunc [1] [1 1 2]) => [1 2]
01:10zematis)
01:17kenrestivois there some way to exec a file (with shell) that's in a uberjar?
01:17kenrestivothere's an embedded ! put in there by... i dunno, java? it's not making the shell happy, i.e.:
01:17kenrestivojava.io.IOException: Cannot run program "file:/home/djdash/target/djdash-0.1.1-standalone.jar!/scripts/nowplaying.py": error=2, No such file or directory
01:18Kneivakenrestivo: you can unzip the jar
01:18kenrestivono, i mean, from within the clojure code, running in the uberjar
01:19amalloykenrestivo: it's not a file, it's an entry in a zip file. you can run that iff your OS/shell has a way to treat an entry in a zip file as if it were a file on disk
01:19kenrestivointeresting. i'll find out if it can.
01:20kenrestivogoogling this will not be fun
01:23amalloyyou probably can't
01:23amalloyi mean, you could like...unzip the file to stdout, parse out the file you want, and pipe that to sh or whatever
01:24amalloybut is that really how you want to spend an evening
01:28Kneivazematis: http://stackoverflow.com/a/1511428 maybe?
01:29kenrestivoamalloy: very true. i'll just dump the script in the filesystem somewhere and call it that way
01:44zematisKneiva: nope, doesn't work :(
01:44zematisremoves items multiple times
01:44Kneivazematis: Can you give another example of what you want?
01:45zematisexcuse me, removes all instances of the items in the set
01:45zematis(remove #{1} [1 1 2]) => [2]
01:46zematisfor ease of comparison, I wanted:
01:46zematis(remfunc [1] [1 1 2]) => [2]
01:46zematis(remfunc [1 2 3] [1 2 2 3 3 3]) => [2 3 3]
01:48amalloyzematis: you can't really do that very efficiently if they're both vectors
01:49roelofif I have this code : http://lpaste.net/142334 why do I see this error : http://lpaste.net/142335
01:49zematisamalloy: lists would be fine too
01:49amalloybut if you took the "things to remove" and made it into a multiset you could do it efficiently, like (multi-remove '{a 1, b 2} '[a b c a b c]) => '[c a c]
01:50amalloylists are even worse. you need an actual data structure with fast lookup, if you want to look compare items in two collectinos
01:50zematisah yes, was thinking removal time, not lookup time :)
01:50zematisthat's what I'm looking for. Thanks!
01:51amalloyi mean you still ahve to write multi-remove
01:51amalloybut it's not hard with that API
01:54zematiswell, can't always have thing the easy way
01:58amalloynote also that you can use clojure.core/frequencies to convert your original removal list into a removal map
01:58zematisroelof: you have two '(' s before map
01:59zematisamalloy: i've looked at my usecase and ended up implementing the function "duplicates: [coll
02:00zematis]" instaed
02:00zematisbut I'll keep that in mind when this comes up again.
02:02zematisroelof: so the outer wrapping '(' is trying to execute the first item it's given, which is the lazy-sequence generated by map. But the sequence isn't a function, so it can't be executed.
02:03amalloyzematis: "call as a function", not "execute"
02:03zematisthanks )
02:03zematis*:)
02:10roelofThanks, ir works, Is this a good clojure way to make the fib numbers ?
02:16roelofthen it would be this using only anomous functions : (fn [n] (take n (map first (iterate (fn [a b] [b (+ a b)] ) [0 1]))))
02:24roelofsomeone a tip how I can improve this. This looks even long as a loop - recur solution ?
02:26amalloywell, remove the n and the take, so you can just return the infinite seq
02:38roelofamalloy: I did use the take n because I want only some numbers not the whole sequence
02:39amalloywhat i mean is, if you are implementing "produce fibonacci numbers", you want a function that produces all of t hem, and then you can call take on that. you don't want to *have* to specify an n to get any fibonacci numbers
02:44roelofoke, but what if I want one time three numbers and the other time 4 times, That is why im using the n
02:47amalloythen you can just write (take 3 (fibs)) and (take 4 (fibs)), or (defn n-fibs [n] (take n (fibs))) (n-fibs 3) (n-fibs 4)
02:47amalloyit's just unnecessarily limiting to tie your fibonacci function to the take function
02:48roelofoke, I try to find a solution to this problem: https://www.4clojure.com/problem/26 and there a x or n is given
03:00roelofamalloy: did you give a answer after my last question. My wife pressed all my sites away
03:01amalloyno. i think for an exercise site like 4clojure it's perfectly fine to bake in the n. i certainly would
03:01amalloybut i guess we shouldn't have written the problem that way! (= (take 3 (__)) ...) would have been a better problem
03:03roelofoke, then I have now a loop - recur and this solution.
03:13roelofchips : this one (fn [n] (map first (iterate (fn [a b] [b (+ a b)]) [0 1]))) fails the unit test of 4clojure
03:15luxbock,(def fib ((fn [f] ((fn [x] (x x)) (fn [x] (f (fn [xx] ((x x) xx)))))) (fn [f] (fn [x] (condp = x 0 0 1 1 (+ (f (dec x)) (f (dec (dec x)))))))))
03:16clojurebot#'sandbox/fib
03:16luxbock,(fib 10)
03:16clojurebot55
03:16luxbockyay
03:19roelofCan anyone explain why my solution fails on 4 clojure but works on my own box
03:19luxbockroelof: if you mean the snippet you posted above, the argument `n` isn't used anywhere
03:20roelofoke, somehow the take part is missing
03:22roelofalso this one fails : (fn [n] (take n (map first (iterate (fn [a b] [b (+ a b)]) [0 1])))) :(
03:23emautonI'm curious whether there are any ongoing efforts to improve Clojure's REPL error output? I kind of get by, having some Java background, but I have a friend who's finding some of the obscure errors quite frustrating.
03:23amalloyroelof: the 4clojure problem thinks fibs start at 1, not 0. another problem with the puzzle
03:23luxbockroelof: you are passing too many arguments to the `f` that `iterate` takes
03:24luxbockroelof: you probably meant to use `[[a b]]` instead of `[a b]` there
03:24amalloyoh that too
03:27roelofthanks , chaning it to [ 1 1 ] instead of [0 1] and the extra [] around the [a b] did the job
03:27roelofcan anyone explain why the extra [] must be added ?
03:28lumabecause the function takes only one parameter, a vector of two numbers
03:28lumathe [[a b]] is a destructuring that takes one vector and binds its first item to a and second item to b
03:29roelofoke, thanks
03:29roelofnow I have to figure out how to reverse a seq without using reverse.
03:35roelofI think map and conj can do the job
03:36lumahow would map do it?
03:39roelofluma: that is one of the things I do not know at the moment. One way or the other I need some sort of accumenlator to store the new map I think
03:41amalloyroelof: indeed! and "accumulator" is a word that should immediately make you think "reduce", not "map"
03:41roelofoke, at this moment just doig some thinking
03:43roelofI can also look at reduce. I always thought that reduce was more about adding , counting where the output is one things and not a whole map
03:49amalloywell, the problem you'll run into with map is that it can only transform one element at a time, and leave it in the same place
03:49amalloyyou can't use it to do "global" transformatinos across a whole sequence
03:51roelofoke, then I will do some experiments today how I can use reduce . Thanks so far for the help
04:20marshzor_exit
05:29nXqdhi guys, I'm trying out component system of Stuart, but I'm not so clear how to use one dependency in a component
05:29nXqdfor example : I have user component, I have one function user-add , and it needs connection from :db component
05:30nXqdhow do I get the conn from db component in user component. ( Just assume that I have all configuration regarding dependency-map and system-map setting up correctly )
05:41sveriHi, how can I convert a map into a vec? I came up with (flatten (into [] {:foo :bar})) but that looks so much code
05:42schmir,(seq {:foo :bar})
05:42clojurebot([:foo :bar])
05:44sverischmir but thats also wrapped into a seq
05:44oddcully,(mapcat identity {:foo :bar :1 :2})
05:44clojurebot(:foo :bar :1 :2)
05:44schmir,(apply concat {:a 1 :b 2 :c 3})
05:44clojurebot(:a 1 :b 2 :c ...)
05:45sveriOk, thank you both. I guess I just pick one randomly :D
06:14TEttinger,(apply vector {:a 1 :b 2}) ;; not sure how this works
06:14clojurebot[[:a 1] [:b 2]]
06:14trisshas it been decided that we should encourage namespace aliases?
06:14TEttinger,(apply vec {:a 1 :b 2}) ;; not sure how this works either
06:14clojurebot#error {\n :cause "Wrong number of args (2) passed to: core/vec"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (2) passed to: core/vec"\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" 36]\n [clojure.lang.AFn applyToHelper "AFn.java" 156]\n [clojure.lang.AFn app...
06:15TEttingertriss: as in, (:require [clojure.string :as s])
06:15TEttinger?
06:15trissyep.
06:15trissDoes it say this anywhere?
06:16TEttingerAFAICT that's very common and encouraged heavily over (:use [clojure.string]) or referring to all of it
06:17TEttingernotably for this example, (:use [clojure.string]) will make the clojure.core fn replace not available by its normal name (you can use clojure.core/replace to use it, but replace will be the one in string, confusingly)
06:19TEttinger~use
06:19clojurebotI am putting myself to the fullest possible use, which is all I think that any conscious entity can ever hope to do.
06:19TEttingerha
06:19TEttinger~require
06:19clojurebotexcusez-moi
06:26toluHi
06:27toluWhat’s the best web framework to use in clojure
06:29scottjtolu: compojure is by far the most popular and a good starting point
06:29toluscottj: thanks
06:33toluscottj: what about Hoplon? I just a few things about it now
06:34tolu: scottj: what about Hoplon? I just read a few things about it now
06:35scottjtolu: idk much about it. luminus is probably second most popular.
06:36toluscottj: alright
07:07javjarferHi there! Anyone using seesaw knows if frame min-size is respected while resizing?
07:27crockethttps://upload.wikimedia.org/wikipedia/commons/1/1d/Newlisp-lisp-thought.png
07:31roelofHello, for 4clojure I have to reverse a seq without using reverse. So I thought I could do it this way (reduce (conj {} xxx ) list) but I cannot figure out what must be xxxx. I do not have a name for a item as far as I know
07:31roelofwho can give me a tip here ?
07:33lumawhat is the empty map in conj?
07:33lumawhy would you conj anything onto a map if you want to reverse a seq?
07:34roelofluma a empry map is {} as far as I know
07:34dstockton,(reduce #(conj %) [1 2 3 4] '())
07:34clojurebot[1 2 3 4]
07:34lumayes, why do you have an empty map there
07:34dstockton,(reduce #(cons %) [1 2 3 4] '())
07:34clojurebot[1 2 3 4]
07:34luma,(reduce conj '() [1 2 3 4])
07:34clojurebot(4 3 2 1)
07:35dstockton:D
07:35roelofI thougtht it was needed. I have to put the answer somewhere ?
07:36lumabut the answer isn't a map, it's a sequence (and list works well in this case)
07:37roelofwierd. I thought conj needed two arguments. A seq and a item. On your solution I see only 1 '() or is the list now a argument for reduce and for conj ???
07:38lumayes, it is given two arguments there
07:39lumathe first argument to reduce is a function that takes two arguments (the accumulator and the current item from the input sequence)
07:40lumaand the initial value for the accumulator is the empty list '()
07:41roelofthanks but sometimes the clojure syntx can be very confusing
07:42lumawhat's confusing about reduce?
07:42roelofI thought the first argument of reduce is the conj function and the second one the list. Conj needs also 2 argument the element and a list.
07:43lumayes, and that's how reduce calls it
07:44lumabasically, (reduce conj '() [1 2 3 4]) is equal to (conj (conj (conj (conj '() 1) 2) 3) 4)
07:44TMAroelof: consider: (reduce (fn [accumulator item] (conj accumulator item)) '() [1 2 3 4])
07:46TMAroelof: you can then simplify (fn [accumulator item] (conj accumulator item)) to just conj by eta conversion
07:46roelofeta conversion? I have still a lot to read
07:46snowellI think the doc for reduce is worded confusingly
07:47snowellBut once you see it in use once or twice it clicks
07:47tdammerseta reduction means that if you have (fn [x] (f x)), you can reduce it to just (f x)
07:47lumaeta conversion is a lambda calculus thing, don't worry about it
07:47TMAroelof: never mind. eta conversion is a concept from lambda calculus; basically it says that (fn [x] (f x)) is the same thing as f itself
07:48tdammersthat, yeah
07:48tdammersit's a bit more obvious in Haskell/ML-like languages, where it amounts to removing the last argument from both sides of the "equation"
07:49tdammersf x = g x => f = g
07:49roelofThanks , I hope he click will come after more and more practice
07:50TMAroelof: it eventually clicks
07:51snowellroelof: reduce didn't really click with me until last week when oddcully and I were helping you with it :)
07:51roelofi hope so. so when I use a anymous function like (fn (counter) (inc counter) I can also make it smaller that way ?
07:52lumayes, that anonymous function is exactly equal to just "inc"
07:52oddcullyroelof: yes (but you have wrong syntax there)
07:53oddcullyroelof: #(inc %) (fn [x] (inc x)) inc are all three a function to increment one passed argument
07:53snowellHaha sorry I summoned you, oddcully!
07:53oddcullyroelof: so you can do this: (#(inc %) 42)
07:54oddcullysnowell: haha! now you have banish me
07:54TMAroelof: you can safely continue to use (fn (counter) (inc counter)) if it provides you with better understanding
07:56roelofoke, I was thinking about a solution for counting for 4 clojure which now looks like this : (fn [list] (reduce (fn [counter _] (inc counter)) 0 list))
07:56roelofI wonder if I could make it smaller
07:57lumanot really, since the function must accept two parameters
07:57TMAroelof: there is no need to have the smallest code; that will come as you will advance
07:58roelofoke, I will leave it this way then and do whatever I think is better working for me.
07:58roelofThanks all
07:58lumayou could do it a bit differently: (fn [list] (reduce + 0 (map (constantly 1) list)))
07:58TMAroelof: you can cheat a bit with #(%) shortcut: #(reduce (fn [c _] (inc c)) 0 %)
07:59snowellGood luck, roelof :D
07:59roelofthanks
08:00oddcullyroelof: if you dont like the wrapping of (fn [list] (... list)) you could learn about partial
08:00roelofand again thanks , your guys/girls are learning me very much and I appreciate it also a lot
08:01roelofoddcully: partial is the next chapter I want to read in the programming clojure book
08:01oddcullywhich brings me to: is there are bizarro-partial, that gens a fn, that has more arity than the wrapped one (as for the inc case in a reduce)?
08:02tdammershow would that work? what would the generated fn do?
08:02tdammersI don't think there's a generic way of having this make sense
08:03tdammersit would for specific cases, such as turning a function that takes exactly one vector into a variadic fn
08:03TMAsomething like (defn bizarro-partial [f] #(apply f %&)) ?
08:03tdammersbut not as generic as currying
08:04oddcullyTMA: nice!
08:05crocketWoohoo?
08:06TMA,((partial inc) 1 2 3)
08:06clojurebot#error {\n :cause "Wrong number of args (3) passed to: core/inc"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (3) passed to: core/inc"\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" 40]\n [sandbox$eval25 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval25 invo...
08:07oddcullyTMA: yes does not work for the reduce case
08:07TMA,(apply inc [1 2 3])
08:07clojurebot#error {\n :cause "Wrong number of args (3) passed to: core/inc"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (3) passed to: core/inc"\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" 40]\n [clojure.lang.AFn applyToHelper "AFn.java" 160]\n [clojure.lang.AFn app...
08:07tdammersone could of course make an uncurry fn
08:08tdammers(defn uncurry [f] (fn [arg & args] ((f arg) args)))
08:08tdammerssth like that
08:12crocketWill tail call optimization be useful in clojure?
08:16anewell, yes
08:19Bronsarelatively useful, we don't use recursion as much as in, say, scheme
08:24LeonidasOne could program CPS in Clojure then, but I doubt that people would like that.
08:26roelof /me hopes once he could make a sort of bank account programm which can leads to a accounting programm but he think he has to learn a lot before he can begin
08:29roelofbut for now I have to leave. I have to go to the dentist :(
08:30tdammersLeonidas: why not?
08:30troydmhow do I remove complety from mapping namespace?
08:30tdammersmatter of convenient abstractions, I'd think
08:34Leonidastdammers: Maybe you're right.
08:35tdammersCPS certainly isn't a silver bullet, but when it's appropriate for the problem at hand, performs well, and makes for readable code, I doubt anyone sane would oppose
08:36Leonidaswell, readable code is arguable.
08:37tdammersarguably so :D
09:04troydmguys
09:04troydmlet's say I have a function that I want to declare later
09:04troydmbut I need to call it for a definition
09:04troydmhow I can I somehow delay the evaluation of a function?
09:05troydmcan I somehow make it lazy so the entire thing be evaluated only later?
09:05namrasounds like a promise
09:05tdammerswait
09:05troydmI'll try to write a simple example of a problem that I have
09:06tdammersdo you want to delay the function evaluation, or do you want to use a function before it is defined?
09:06tdammersi.o.w., are we talking runtime "before" here, or code-writing-time "before"?
09:11troydmtdammers: https://www.refheap.com/278e13f6d25ee28dee6a7287b
09:11troydmsimply speaking I want to delay the evaluation of a variable definition until the function is defined
09:13tdammersuhm
09:14tdammersI don't think that's how clojure's execution model works
09:14tdammersbest I can think of would be to wrap f in a promise
09:17TEttinger(doc delay)
09:17clojurebot"([& body]); Takes a body of expressions and yields a Delay object that will invoke the body only the first time it is forced (with force or deref/@), and will cache the result and return it on all subsequent force calls. See also - realized?"
09:21TEttinger,(delay (bart-simpson))
09:21clojurebot#error {\n :cause "Unable to resolve symbol: bart-simpson in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: bart-simpson in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol:...
09:21TEttingerthe bot might be dereferencing to print
09:22TEttinger,(delay 5)
09:22clojurebot#object[clojure.lang.Delay 0x7c2e76a0 {:status :pending, :val nil}]
09:22TEttinger,(def d (delay 5))
09:22clojurebot#'sandbox/d
09:22TEttinger,@d
09:22clojurebot5
09:22TEttinger,(def d (delay (homer)))
09:22clojurebot#error {\n :cause "Unable to resolve symbol: homer in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: homer in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: homer in this...
09:22TEttingeryou could maybe use declare
09:23TEttinger,(declare bart-simpson)
09:23clojurebot#'sandbox/bart-simpson
09:23TEttinger,(def d (delay (bart-simpson)))
09:23clojurebot#'sandbox/d
09:23TEttinger,(defn bart-simpson [] "ay carumba")
09:23clojurebot#'sandbox/bart-simpson
09:23TEttinger,@d
09:23clojurebot"ay carumba"
09:24TEttingertroydm: ^
09:26borkdudeI have a println in my compojure end point. When I post only once, it's printing three times. I have checked this side effect by incrementing an atom, which is only happening one time. What could be wrong with my println?
09:38troydmTEttinger: another question
09:38troydmlet's say I have not functions but just variable definitions
09:38troydmand I want another to reference one not yet declared
09:39troydmsomething like:
09:39troydm(declare f)
09:39troydm(def f2 (+ f 2))
09:39troydm(def f 13)
09:39troydmthere is no other way than using delay?
09:40tdammerswhat's wrong with delay?
09:40troydmtdammers: u need to dereference it before using
09:41opqdonuttroydm: that would require a smarter compiler
09:41troydmopqdonut: yeah, seems so
09:41tdammersopqdonut: not much smarter though
09:41opqdonuttdammers: yeah, only one toposort
09:41opqdonutbut still
09:41opqdonutwith macros it would be flaky
09:42tdammersI think the bigger tradeoff is that it would make laziness implicit, which is something that you can only really get away with when your language has no side effects at all
09:42opqdonutand also, a clojure file can interleave side-effectful things between defs
09:42opqdonutso yeah, what tdammers said
09:43tdammersfwiw, haskell does it, but this choice alone makes for a radically different language
09:43troydmseems something that Haskell is for
09:43troydmI guess I'll have to stick with references
09:52troydmbtw is there a macro for delay?
09:52troydmlike (defd f body) that would result in (def f (delay body)) ?
10:14noncomadding quil dependency to my current project makes leiningen fail to compile it
10:14noncomthe error is "class "org.bouncycastle.crypto.digests.SHA3Digest"'s signer information does not match signer information of other classes in the same package"
10:15noncomi have run deps tree and found that quil requires these "bouncy" deps too, so does the buddy library that i use in my project
10:15noncomsince quil uses them for PDF export and i don't need that, i thought i would exclude them
10:16noncombut after i add them to quil exclusions, the project breaks down again - now it fails to require the namespace that contains "buddy" requires
10:16noncomwhat do i do with that
10:55noncomnp, solved
10:58TMA(inc rubberduck)
11:54zxcHello! Can someone help me with vim fireplace, please? I can't connect to the nREPL server
11:57zxcI've tried to google it, but there was nothing
11:58oddcullyzxc: you ran your `lein repl` and started vim in that same dir where the project.clj is? it should work out of the box
11:59oddcullyif you have started the lein repl later, you can do `:Connect` in vim and follow the instructions
12:01zxcOkay, I will try it
12:03zxcI still have to give a port
12:03zxcoddcully: Although I've started it in a dir with project.clj
12:04oddcullyif there is no .nrepl-port file, then you have to use the port (or the whole url) the repl prints
12:04zxcCan you specify? I've never done magic things like that
12:04oddcullyit's the first line the repl prints
12:04zxckay, thanks!
12:05oddcullyyou can use the whole "uri" there `:Connect nrepl://localhost:666`
12:05zxcIt works! Thanks a million
12:07zxcoddcully: Also, is there a way of deleting one curly bracket while using paredit?
12:10oddcullyonce in trillion parens, there is some inballance. i use `r<space>` to get rid of it
12:11zxcThanks again!
13:14cloj_devcan you put println in a let statement?
13:17hiredmanclojure has expressions, not statements
13:17hiredmanyou can put an expression that is a call to the println function any place you can put an expression
13:23trissbut note that println always returns nil!
13:23trisssometimes I make a p fn that prints and returns so I don't have to move code about as much when printing
13:24triss(defn p [x] (println x) x)
13:27oddcully,(let [x {:a :b} y (doto x println)] y)
13:27clojurebot{:a :b}\n{:a :b}
13:30trissoddcully: that might come in handy. thanks!
13:40TimMcI have a unit test that tries to exercise a macro that emits a defonce. If I re-run those tests, i get failures, because state is accumulating in the object ref'd by the defonce.
13:40TimMcIs there an easy way to just remove that var from the test ns?
13:41rhg135ns-unmap
13:46TimMcThanks!
14:03perrpellI'm using [org.clojure/tools.namespace "0.2.11"] for auto reload in the repl of files modified in the project.
14:04perrpellWhen I edit an existing function, the edits are picked up and all is good.
14:05perrpellBut if I add a new function to a namespace, the new function is not visible in the repl after (refresh). Can anyone help me understand why that is?
14:05perrpellThanks in advance.
14:06rhg135Are you by chance using aliases?
14:06rhg135If so they point to the old namespace
14:07perrpellNo am not using aliases. Just boring ole (require) at the repl.
14:36justin_smithperrpell: require with the :refer argument?
14:36perrpell@justin_smith sorry I should have said :as
14:37justin_smithperrpell: :refer and :as can be used together, I'm specifically asking if :refer was used at all
14:37perrpellHold a second let me check.
14:39perrpellThe only :refer that is used is when requiring the repl tools - (require '[clojure.tools.namespace.repl :refer [refresh]])
14:39perrpellThat comes directly from their docs.
14:40justin_smithOK - yeah, that's optional - the reason I ask is refer needs to be re-run if you change stuff, because of how refer works (aliasing things), but if you did (require foo.bar :as bar) then define foo.bar/baz, bar/baz should work
14:40justin_smithwhether that's done by doing a require :reload on foo.bar or switching to foo.bar and defining baz or whatever
14:41perrpell@justin_smith what do you use to auto reload all your files on the repl? Is there another tool set?
14:42justin_smithperrpell: I typically use (require 'foo.bar :reload) or (require 'foo.bar :reload-all), but sometimes use (refresh)
14:43justin_smithperrpell: oh! if you did the require :as outside the file's namespace def (eg. in the repl), refresh will obliterate that
14:43justin_smithperrpell: and you will need to redo your require in the repl if you used refresh in that case
14:44justin_smithperrpell: the difference with refresh is it actually destroys all the namespaces and their vars and rebuilds from scratch, so that can break mappings that are not defined in the source files (eg. repl mappings)
14:45perrpelljustin_smith: yes the (refresh) succeeds when I edit an existing function in any given package (e.g. foo.bar).
14:45perrpellBut if I add a function to foo.bar and then do a (refresh) the new function doesn't get picked up in the refresh.
14:47justin_smithperrpell: are you adding it in the repl, or changing the source? because if you change the source it should exist after a refresh
14:49perrpelljustin_smith: in the source for sure.
14:53skeuomorf,(def x (.getBytes "test"))
14:53clojurebot#'sandbox/x
14:54skeuomorf,(. x length)
14:54clojurebot#error {\n :cause "No matching field found: length for class [B"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: length for class [B"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 315]\...
14:54skeuomorfhmm
14:58justin_smith,(. x count)
14:58clojurebot#error {\n :cause "No matching field found: count for class [B"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching field found: count for class [B"\n :at [clojure.lang.Reflector getInstanceField "Reflector.java" 271]}]\n :trace\n [[clojure.lang.Reflector getInstanceField "Reflector.java" 271]\n [clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 315]\n ...
14:59justin_smith,(alength x)
14:59clojurebot4
14:59justin_smithskeuomorf: arrays don't have methods like classes do! it's super weird
14:59skeuomorfjustin_smith: Yes!
14:59justin_smithskeuomorf: array.length in java is actually a weird pseudo-method-call syntax but not a real method
15:00emautonOh, repeat from this morning just in case any awake-people have opinions: I'm curious whether there are any ongoing efforts to improve Clojure's REPL error output? I kind of get by, having some Java background, but I have a friend who's finding some of the obscure errors quite frustrating.
15:00skeuomorfjustin_smith: interesting
15:01justin_smithemauton: there are unofficial projects but aviso/pretty, but it definitely is not a priority of the core team
15:01emautonI had a good look around the community wikis & JIRA and while there's a grab-bag tag "errormsgs" and some old design wiki notes from 2011-2013, there wasn't a lot.
15:01emautonjustin_smith: I'll take a look at that, thanks
15:02justin_smithemauton: basically any improvement on error handling / messages that degrades performance even a little has historically been a no-go for the core language
15:02emautonThat's useful context, thank you.
15:02justin_smithemauton: hlshipp also has other related projects to aviso/pretty, for example allowing you to push a "context" onto a custom stack so that things in core.async or such can give more informative errors
15:03justin_smithforgetting the name off the top of my head, maybe rook?
15:04justin_smithemauton: oh, rook is his router thing, which uses tracker, that's the one I was thinking of https://github.com/AvisoNovate/tracker
15:04justin_smithtracker is the one that helps provide better error context
15:04emautonGreat, yes, having a look through their repos now.
15:07emautonI think "pretty" will already be a big improvement. Wonderful, thanks for the links.
16:17arryhi! i've got a question: when you use WebJars in a Ring application, where are the asset files actually served from? It seems like witchery to me :)
16:42justin_smitharry: the jar is a zip file, the assets typically are served out of the zip file itself (which means uncompressed from ram)
16:43justin_smitharry: of course extracting that jar/zip into a directory, and serving from the resulting files is also an option
16:44arrycool
16:45arryi was wondering if the files were packaged with the app, or whether they were downloaded from a CDN at some point during app running (WebJars site mentions a CDN)
16:47mgaare_any way to alias things I'm importing? right now I'm doing (import foo.Bar biff.Bar) and getting a duplicate name problem
16:49mgaare_and by problem I naturally mean exception :D
16:49amalloyno
16:49amalloyyou just have to choose to use the fully-qualified name for one of them
16:51mgaare_ah, I see
17:12phorseWhat's the best way to include an anti-forgery token in a reagent form?
17:28justin_smithphorse: you can get it into the reagent state when the page data is sent, then have the form's component grab that data
17:28justin_smithphorse: so assuming you have some ajax json request, have the anti-forgery token be part of that payload?
17:35phorsejustin_smith: I'm a little confused. I'
17:35phorse've got a basic compojure app that I'm adding reagent fanciness to, so all my pages are built server side.
17:36Glenjaminif you're doing json, you don't actually need a csrf token
17:36phorseI'm just dipping my toe in the water of clojurescript - will this require me to rework the server side to be more rest-ish?
17:36Glenjaminoh, the simplest thing to do would be to drop it into a hidden form field as normal, and use JS to read it out
17:37phorseOk, so just have it in the response and then use js to copy it into the form?
17:38phorseIs this the usual way to handle sharing between server and client? Say, if I want to access the user session, I should embed it in the page?
17:48Glenjaminbasically, yes
17:48Glenjaminor you can make a little api thing
17:51phorseJust to make sure I understand the api point: Client sends request for resource (GET /home), then the server packages that up in JSON and sends it over?
17:52justin_smithphorse: that would be normal for reagent, yeah, since reagent is a tool for rendering on the client side
17:53phorseOk, thanks. That should be enough to go on for a while.
20:34zexperimentevening friends
20:37justin_smithevening