#clojure log - Apr 26 2015

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:05 nbeloglazov: Is there a way in core.typed to check namespace without throwing an error and only printing found issues?

0:05 I'm trying to gradually annotate namespace from emacs and constantly invoking check-ns to test it.

0:09 allenj12: test

0:09 arrdem: nbeloglazov: the #typed-clojure folks will probably know

0:09 offhand I can't say I do

0:10 nbeloglazov: Thanks. Will try there.

0:10 arrdem: I think there's a typed clojure emacs plugin that deals with that for you

0:10 nbeloglazov: Yeah, but I'd rather start with "low-level" :)

0:10 arrdem: eh tooling exists to be used :P

0:57 dumptruck: stuck on another koan... "Or use the names of existing functions" (= __ (map nil? [:a :b nil :c :d]))

0:57 any hints?

0:58 interestingly... i happened to remove the __ and save and it passed...

0:58 arrdem: dumptruck: what number is this?

0:58 ##(= 1)

0:58 lazybot: ⇒ true

0:59 dumptruck: oh right

0:59 arrdem: :P

0:59 dumptruck: it's 08_higher_order_functions

0:59 3rd one

0:59 but

1:00 ,(nil? nil)

1:00 clojurebot: true

1:00 dumptruck: er.. not what i meant

1:00 ,(nil? :a)

1:00 clojurebot: false

1:00 dumptruck: if that's the first mapping

1:01 how does that not invalidate the test with (= (map nil? [:a :b nil :c :d]))

1:01 (= false)

1:01 ,(= false)

1:01 clojurebot: true

1:01 dumptruck: oh.

1:01 arrdem: ∀ x (= x) == true

1:02 ##(map nil? [:a :b nil :c :d])

1:02 lazybot: ⇒ (false false true false false)

1:02 dumptruck: the hint it is giving me is throwing me off

1:02 "Or use the names of existing functions"

1:03 is it just referring to nil?

1:03 i guess so...

1:04 arrdem: honestly not sure

1:11 TEttinger: dumptruck: this list of koans? https://github.com/functional-koans/clojure-koans/blob/master/src/koans/08_higher_order_functions.clj

1:12 I believe that's meant to be a continuation of the previous sentence

1:12 (= [false false true false false] (map nil? [:a :b nil :c :d]))

1:12 ,(= [false false true false false] (map nil? [:a :b nil :c :d]))

1:12 clojurebot: true

1:13 dumptruck: yeah

1:13 i mean, that's what i put

1:13 i thought it was asking me to put a function name

1:14 TEttinger: I think it was referring to its use of nil?

1:14 instead of (fn)

1:14 dumptruck: right

1:15 TEttinger: you're totally right, it's worded poorly

1:22 fowlslegs: Is there a way to use a local variable name from function A in function B is function A calls function B?

1:22 Let me try to write this clearer.

1:24 I want to write something like

1:24 ,(defn b [] local-var-from-a)

1:24 clojurebot: #error{:cause "Unable to resolve symbol: local-var-from-a in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: local-var-from-a 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: local-var-...

1:25 fowlslegs: But I won't be able to resolve local-var-from-a.

1:26 lvh: fowlslegs: there's two ways to do this

1:26 fowlslegs: the obvious way is to pass the var as an argument to b

1:26 fowlslegs: the less obvious way is ^:dynamic, but I'd be very surprised if that's actually a thing you want to use here

1:27 fowlslegs: But if function a looks like (defn a [] (let [local-var-from-8 42] (b))

1:28 puredanger: The whole point of local vars is to have local lexical scope. If you want it in b, pass it in.

1:28 fowlslegs: For what I'm doing I can't pass the var as an argument to b.

1:28 dumptruck: why not

1:28 fowlslegs: Sorry I should have made that clear.

1:29 dumptruck: (defn a [] (let [local-var-from-8 42] (b local-var-from-8))

1:29 no?

1:29 clojurebot: no is tufflax: there was a question somewhere in there, the answer

1:29 fowlslegs: Because I want my file to run with a certain system and to do that I'd have to modify parts of the system that would break it for other files.

1:30 TEttinger: fowlslegs: there's technically nothing preventing you from running def inside function a

1:30 it's not at all encouraged

1:30 arrdem: Oxcart will whine if you try that :P

1:30 puredanger: Well I'd say this is the wrong overall path, but dynamic vars would give you the dynamic scope you seek

1:31 dumptruck: can you not overload b?

1:31 puredanger: Don't use def, bleh

1:32 TEttinger: fowlslegs: I would say, make a third def at outer scope, an atom or something that you just assign the value from a

1:32 this way only the most recent call to a matters

1:32 fowlslegs: Let me explain the structure better. I have full control over b, but not a. a calls b as an anonymous function and gives it exactly

1:32 dumptruck: like

1:33 fowlslegs: one argument which is not the argument I need. However, a also defines a variable, which changes as it loops over b

1:33 and I want to use that variable.

1:33 dumptruck: (defn b ([] (b :default-value)) ([a-value] ...))

1:34 arrdem: that is in fact the idiom for implicit arguments

1:34 puredanger: Well, Clojure doesn't work that way

1:34 TEttinger: if you don't have control over a you can't reach in and and pull out its internal vars without some serious hacks

1:34 dumptruck: ah

1:34 TEttinger: it may be possible

1:34 not a good idea

1:34 puredanger: You shouldn't want it to work that way :)

1:34 fowlslegs: TEttinger: Haha indeed. I was hoping the experts here could help me with that.

1:35 TEttinger: well hm

1:35 so A is called without your control?

1:35 fowlslegs: Yes.

1:35 TEttinger: not even in your lib?

1:36 fowlslegs: Is there some way I can make b a macro that creates a function that grabs this local-var?

1:36 TEttinger: I mean you must have access to the source, otherwise you wouldn't know about the loop

1:36 puredanger: If b was a macro you could prob get to it via &env

1:36 fowlslegs: TEttinger: I do. I just really, really don't want to change it.

1:37 puredanger: But to be clear, this is a terrible idea :)

1:37 fowlslegs: TEttinger: My file will not be accepted to the examples if I modify the system files.

1:37 TEttinger: examples?

1:37 clojurebot: examples is api examples

1:37 fowlslegs: puredanger: I love terrible ideas.

1:37 I have about 4-5 per minute.

1:38 TEttinger: if there's an acceptance process you really really don't want to be hacking local scope that is not your own?

1:38 arrdem: TEttinger: you left a -? on that bud

1:39 TEttinger: it's the expression my eyebrows are making, arrdem

1:39 puredanger: Macros expand in their caller and have access to an implicit &env that includes locals iirc

1:40 fowlslegs: puredanger: Can you give me an example of how I might do this or point me to relevant documentation?

1:41 puredanger: No, on my phone sorry

1:41 arrdem: http://blog.jayfields.com/2011/02/clojure-and.html

1:41 fowlslegs: Honestly the fact you might be able to do this is not very comforting from a security standpoint.

1:42 arrdem: aw dnolen is afk

1:45 TEttinger: ,(defmacro show-form [a b] `(println ~@(next &form)))

1:45 clojurebot: #'sandbox/show-form

1:45 TEttinger: ,(let [alpha 1 beta 2] (show-form alpha beta))

1:45 clojurebot: 1 2\n

1:48 arrdem: can I use CIDER to connect twice to the same nrepl instance?

1:48 TEttinger: ,(defmacro B [] (do (print (keys &env)) 42)

1:48 clojurebot: #<RuntimeException java.lang.RuntimeException: EOF while reading>

1:48 TEttinger: ,(defmacro B [] (do (print (keys &env)) 42))

1:48 clojurebot: #'sandbox/B

1:50 TEttinger: ,(loop [a 0] (if (> a 3) (print "Done!") (do (B) (recur (inc a)) )))

1:50 clojurebot: (a)Done!

1:51 TEttinger: ,(defmacro B [] (do (print (vals &env)) 42))

1:51 clojurebot: #'sandbox/B

1:51 TEttinger: ,(loop [a 0] (if (> a 4) (print "Done!") (do (B) (recur (inc a)) )))

1:51 clojurebot: (#object[clojure.lang.Compiler$LocalBinding 0x1f5c0126 clojure.lang.Compiler$LocalBinding@1f5c0126])Done!

1:51 TEttinger: woah

1:52 ,(defmacro B [] `(println ~@(keys &env)))

1:52 clojurebot: #'sandbox/B

1:52 TEttinger: ,(loop [a 0] (if (> a 4) (print "Done!") (do (B) (recur (inc a)) )))

1:52 clojurebot: 0\n1\n2\n3\n4\nDone!

1:53 TEttinger: fowlslegs: there you go, maybe

1:53 there are caveats galore

1:53 ,(let [haha "let messes you up"] (loop [a 0] (if (> a 4) (print "Done!") (do (B) (recur (inc a)) ))))

1:53 clojurebot: let messes you up 0\nlet messes you up 1\nlet messes you up 2\nlet messes you up 3\nlet messes you up 4\nDone!

2:05 arrdem: Where would you suggest looking to get started with Ring testing?

2:30 fowlslegs: TEttinger: So really B is calling C and A is calling B, where A has the local var bound in a loop statement as it loops over B among other functions.

2:31 Thanks anyway for your examples and suggestions everyone, but I can't get what I'm looking for with &env

2:31 TEttinger: hm?

6:03 jaaqo: I'm testing my web application routes and am unable to mock out csrf-protection from my queries. Is it a valid approach to create another handler function just to be used in tests, in which the anti forgery is turned off?

6:08 Confusionist: I'm not understanding the following: if I execute (require '[clojure.tools.namespace.repl :refer [refresh refresh-all]]) in a repl, I can subsequently call (refresh) and it does it's job. If I put the exact same line in user.clj (which is being loaded, as confirmed by a println), the 'refresh symbol cannot be resolved. Why is that?

6:11 jaaqo, it's usually easier to just generate a valid csrf token and include it in the request

6:46 sohalt`: Hi, I'm still wrestling with my clojurescript repl and noticed something. I got the repl working a few times (But only after like refreshing the browser >5 times) in my terminal with lein trampoline run -m clojure.main repl.clj, where repl.clj sets up the browser repl. Now when it works the browser starts sending a first POST to "/" with params {:type :ready, :content "ready", :order 1} and after that starts spammin

6:46 g POSTs to "/" (~100 or so) until a GET to strings.js returns with a 404 and then follows a last POST to "/" with params {:type :result, :content "{:status :success, :value \"\"}", :order 105}

6:46 Any ideas, why that could be? Or completely unrelated?

6:47 When it doesn't work (90% of the time) the browser sends the first POST to "/" and then does nothing and the repl sits there waiting with a "Waiting for broswer to connect ..." message

6:49 Oh, and now I'm getting nullpointer messages in the repl

6:50 cljs.user=> Exception in thread "Thread-124" java.lang.NullPointerException

6:50 at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:26)

6:50 at cljs.repl.server$read_request.invoke(server.clj:95)

6:50 at cljs.repl.server$handle_connection.invoke(server.clj:153)

6:50 at cljs.repl.server$server_loop$fn__4477.invoke(server.clj:164)

6:50 at clojure.core$binding_conveyor_fn$fn__4145.invoke(core.clj:1910)

6:50 at clojure.lang.AFn.run(AFn.java:22)

6:50 at java.lang.Thread.run(Thread.java:745)

6:50 zol_: How can I get only the first level of directories inside a directory? like if I have public/images/{a/{1/,2/},b/{1/,2/,3/}, c/{1/}, I want to only get public/images/{a,b,c} as clojure.java.io.File objects

6:52 sohalt`: whoops, clicked on the wrong request before. The last POST to "/" has params {:type :result, :content "{:status :success, :value \"true\"}", :order 113}

6:55 dnolen: sohalt`: sounds like a bug but will need more information

6:55 sohalt`: I haven't encountered this problem in Chrome (which is what I use to develop), but I have noticed that Safari & Firefox often need a refresh or two in some cases.

6:56 zol_: Looks that it is files-seq that makes the call recursively

6:58 sohalt`: I sometimes refreshed >10 times and it still didn't get past that first POST.

6:59 oddcully: ,(.listFiles (new java.io.File "/tmp"))

6:59 clojurebot: #error{:cause "denied", :via [{:type java.lang.SecurityException, :message "denied", :at [clojurebot.sandbox$enable_security_manager$fn__887 invoke "sandbox.clj" 69]}], :trace [[clojurebot.sandbox$enable_security_manager$fn__887 invoke "sandbox.clj" 69] [clojurebot.sandbox.proxy$java.lang.SecurityManager$Door$f500ea40 checkRead nil -1] [java.io.File list "File.java" 1111] [java.io.File listFiles "...

7:00 sohalt`: And I didn't get it to work with inf-clojure, only terminal, although that might simply be coincidence, since from my understanding they do essentially the same. (launch the repl.clj with lein tampoline

7:01 zol_: Fixed it! .listFiles (io/as-file (io/resource "public/images/courses"))

7:03 sohalt`: dnolen: is there anything specific I could try to get more info?

7:04 dnolen: sohalt`: it sounds like a potential server bug

7:04 sohalt`: would be useful to understand why Chrome doesn't have this problem consistently and Firefox does

7:09 noncom: does usage of more than 4-arity fns in clojure give serious overhead?

7:09 or better, what is the additional cost for that?

7:12 dnolen: noncom: there's nothing specific about any particular arity

7:13 noncom: so the answer to your question - no

7:20 noncom: okay, thanks. i just remember that there was that issue with defining more functions of primitive types (incl object) than 4 due to the explosion (4 in power 4 is already too many classes)

7:21 * correction: ...than it is already dont with arity 4 due to the explosion..

7:21 *done :)

8:17 gfredericks: noncom: something around there is true, actually; but if you're not intentionally using primitives that doesn't matter

8:25 Confusionist: Concerning repl workflows: if I start a lein repl and use a user.clj to make some stuff available in the user namespace, is there a way to make it possible to use e.g. (user.str/replace ...) when user.clj contains a [clojure.string :as str]?

8:26 I'm trying to find a way to make common things easy to do, without polluting the app.core namespace and without having to explicitly wrap everything with a separate function in user.clj

8:27 So I e.g. make clojure.tools.namespace.repl.refresh available as user/refresh and I could do the same for those aliased namespaces, but it seems like there should be an easier way

8:34 justin_smith: Confusionist: no, it does not work that way

8:36 Confusionist: though I think vinyasa has similar goals https://github.com/zcaudate/vinyasa

8:38 Confusionist: justin_smith, Thanks, that does sound like what I currently think may be useful

9:02 sobel: i just reload my repl when things get horked up. i could learn a better workflow, but i still build my projects around batch-build ideas, and getting to work in/with a repl is pure gravy

9:04 that said, i'll refresh deps in-repl after editing project.clj, but i usually end up with a broken state i need to restore

9:05 unrelated: anyone here use irclj? i'm trying to figure out how to capture disconnection. hoping i don't have to inspect the interior socket state.

9:05 justin_smith: sobel: I've worked on lazybot.... best of luck

9:08 sobel: that sounds like a 'no'

9:09 justin_smith: more of an "I don't know"

9:09 but yeah

9:09 sobel: figures. irc is still a mutt protocol.

9:11 ugh, the java libs are...java

9:12 Confusionist: sobel, in general you can't reliably determine disconnection from the socket state

9:12 Without a 'ping' or similar in the protocol, you're basically hosed if the other side doesn't nicely close the socket

9:13 sobel: Confusionist: understood; i actually mean timeout.

9:13 i should have said infer rather than inspect ;)

9:14 i might be just clever enough to add clojure to PircBotX

9:46 JanxSpirit: my team is looking to prototype a project using a full-stack Clojure approach with Om - can anyone direct me to the current most mature stack I should be looking at?

9:51 sobel: JanxSpirit: i'm looking at http://www.luminusweb.net/ because it looks fairly complete

9:52 'complete' in the application library sense, or "just add database and a scaling strategy if you need one"

9:59 sveri: JanxSpirit: I put together a template which includes chestnut and luminusweb for code reloading of clj and cljs: https://github.com/sveri/closp However if you only need the cljs part look at chestnut: https://github.com/plexus/chestnut

10:00 Confusionist: Weird: I have a project with speclj where 'lein spec' passes, but 'lein spec -a' immediately raises 'java.io.FileNotFoundException: Could not locate app/core_test__init.class or app/core_test.clj on classpath'

10:00 JanxSpirit: Isobel sveri - thank you

10:01 sobel that is

10:01 sobel: good luck!

10:04 sveri: yea and come back if you have questions

10:04 smorgy: Hi all

10:05 What's the most elegent way to read from a channel only when a predicate is met?

10:05 like having one go-loop processing every odd number, another processing the even ones?

10:07 Confusionist: Ah, eastwood found the problem... but still surprising only the -a trips over it

10:07 oddcully: smorgy: there is `split`

10:11 smorgy: ok, what if there's more consumers than that, so I'll up doing a split of a split of a split...

11:15 catern: dear #clojure

11:15 I would like to partition something on the basis of a predicate

11:16 take-while gives me things up to the predicate becoming false

11:16 brucehauman: group-by

11:16 catern: I think group-by is what you are looking for

11:16 catern: :D

11:16 i think you mean partition-by

11:16 but yes

11:18 brucehauman: catern: partition-by is subtle

11:18 catern: oh

11:18 yeah

11:18 so it is

11:18 brucehauman: catern: group-by actually groups the values

11:18 catern: hmm, actually, I don't think either of these is what I want

11:18 what I want is

11:19 [[true false false false] [true] [true false] [true false false]]

11:20 brucehauman: catern: yeah that is tough

11:20 catern: you only want one true per list

11:20 catern: is there a take-while that does a split?

11:21 ah

11:21 https://clojuredocs.org/clojure.core/split-with

11:21 brucehauman: catern: I dont think that will work either

11:22 catern: well

11:22 hmm

11:22 what I really kind of want

11:22 is https://clojuredocs.org/clojure.string/split

11:22 but for lists

11:23 and with a predicate instead of a regex I mean

12:13 justin_smith: partition-by?

12:13 Confusionist: Is there a simple way in core.match to capture the value of an :or match? So I would like to match [(:or 'foo 'bar) 1 2] and I would like to be able to refer to the value 'foo or 'bar. Of course if I matched somevec, I could simple ask (first somevec), but if could capture it directly, like in a regex named group, that would be nice

12:15 justin_smith: sorry, someone already mentioned that

12:18 ,(map #(apply concat %) (partition 2 1 (partition-by even? [0 1 3 5 2 3 7 4 9 9])))

12:18 clojurebot: ((0 1 3 5) (1 3 5 2) (2 3 7) (3 7 4) (4 9 9))

12:18 justin_smith: not quite

12:18 ,(map #(apply concat %) (partition 2 (partition-by even? [0 1 3 5 2 3 7 4 9 9])))

12:18 clojurebot: ((0 1 3 5) (2 3 7) (4 9 9))

12:19 justin_smith: catern: ^ I think that's your answer

12:28 deanman: How can someone go about deleting a parentheses on cursive ?

12:28 nuwanda__: you're using structural editing?

12:29 deanman: nuwanda__: just started using it so I'm not quite sure what that is. I know that I'm using the "cursive" keybinding set

12:30 justin_smith: deanman: if the pair is empty, you should be able to simple delete them. But structural editing only allows deleting by pairs

12:31 deanman: So if i ultimately want to move that parentheses around then i should be using some other trick ?

12:31 justin_smith: deanman: the keyword to look for is "structural editing", their's various bindings for moving things in and out of paren groups

12:32 gfredericks: hello

12:32 justin_smith: yo

12:32 catern: justin_smith: awesome, thanks

12:33 deanman: justin_smith: Slurp barf etc?

12:33 justin_smith: yup

12:34 deanman: justin_smith: Is that something specific to cursive or something lispy? Where can i find more information what do these terms mean and what they do ?

12:35 justin_smith: deanman: it's a concept a few editors have, cursive has its own key bindings for it

12:35 and yeah, it only works on lispy stuff, but it's not part of the language at all

12:36 deanman: justin_smith: thanks for the tip

12:43 lasergoat: justin_smith: re:https://www.refheap.com/99973. I'm sure you figured it out, but it dawned on me why that fetches an extra item

12:43 weird, actually, that I didn't see it the first time

12:44 justin_smith: oh? ztellman mentioned that it was inevitable with core.async being push

12:44 lasergoat: i mean, i guess that's the general explanation

12:45 the specifics is just that that (>/>! result (first source)) does `first` and then parks on something pulling from the channel

12:45 so there's always something waiting in "parked" mode

12:45 justin_smith: oh, right

12:46 brucehauman: justin_smith: great answer to catern’s question

12:46 lasergoat: so you could do something snazzy with an extra channel that signals "back" that you're ready to pull another item off the upstream source

12:46 but that's sort of ugly

12:46 justin_smith: hmm...

12:47 an abstraction could be reused, and it can be as ugly as it needs to be...

12:47 lasergoat: sure, shouldn't be too hard

12:49 anyway, i'm off; just dropping in to mention it

12:49 justin_smith: thanks

12:51 brucehauman: justin_smith: it was really great meeting you guys

12:51 justin_smith: it's mutual, it was a fun conference

12:52 brucehauman: yeah it was. I really liked Portland. More than I expected

12:56 gfredericks: it's the asheville of the northwest oregon area

12:58 the dumb thing about conferences is you meet a bunch of people you like and then find out that they live far far away from you

13:02 mdallastella: namaste

13:04 brucehauman: gfredericks: I miss you too man

13:04 ;)

13:05 gfredericks: actually I’m gonna get up to Chicago sometime this year. I miss that town.

13:06 gfredericks: doooo it

13:08 and kidnap toby if you do

13:10 brucehauman: gfredericks: thats a good idea

13:12 he’s right next to me

13:13 gfredericks: see it'd be so easy

13:15 lucasb: Hello o/, I'm new to clojure. Is there a function in core that returns the index of the first element in a list that is equal to another or nil if it's not there? Let's say I have '(:a :b :c), given ":c", I want 2 as answer.

13:15 justin_smith: ,(.indexof '(:a :b :c) :c)

13:15 err

13:15 clojurebot: #error{:cause "No matching method found: indexof for class clojure.lang.PersistentList", :via [{:type java.lang.IllegalArgumentException, :message "No matching method found: indexof for class clojure.lang.PersistentList", :at [clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 53]}], :trace [[clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 53] [clojure.lang.Reflector invokeI...

13:15 justin_smith: ,(.indexOf '(:a :b :c) :c)

13:15 clojurebot: 2

13:16 justin_smith: that's jvm clojure only, not clojurescript though

13:17 lucasb: justin_smith: Thanks! That's it.

13:18 arrdem: justin_smith: RFC http://conj.io/contributing

13:19 justin_smith: cool, I'll check that out

13:28 deanman: ,((fn foo [x] (when (> x 0) (conj (foo (dec x)) x))) 5)

13:28 clojurebot: (5 4 3 2 1)

13:30 deanman: I'm having difficulty understanding this snippet.

13:30 justin_smith: deanman: do you have a specific question about it?

13:30 deanman: I do undestand it's an inner function that is being passed 5 as the first argument

13:30 justin_smith: ,(conj '(1 2 3) 0)

13:30 clojurebot: (0 1 2 3)

13:31 deanman: So the first time that gets evaluated it creates a list of (<something> 5)

13:32 <something> is a call to the same function ?

13:32 justin_smith: no

13:32 it creates a list of (5 <something>)

13:33 see my conj example above

13:33 deanman: Ok depending its type gets inserted at the beginning

13:33 justin_smith: depending on what's type?

13:34 deanman: conj always add at the beginning ?

13:34 justin_smith: no, it adds at the "natural" position for that collection

13:34 ,(conj nil 1)

13:34 clojurebot: (1)

13:34 justin_smith: that's the innermost thing that happens

13:34 gfredericks: ,(conj (conj nil 1) 2)

13:34 clojurebot: (2 1)

13:35 gfredericks: ,(conj (conj (conj nil 1) 2) 3)

13:35 clojurebot: (3 2 1)

13:35 gfredericks: etc.

13:35 justin_smith: so does this make more sense now?

13:36 deanman: Yes, it's rather the <something> that troubles me a bit. First time would be (5 <something>) and the <something> is a new call with 4 which returns (4 <something>) right ?

13:37 justin_smith: right

13:37 ,(when false 0)

13:37 clojurebot: nil

13:38 Cust0dian: ,(conj nil 1 2 3 4 5)

13:38 clojurebot: (5 4 3 2 1)

13:43 leifw: is there a thing like this? (with-java-properties {"java.io.tmpdir" "/my/special/directory"} ...forms...)

13:43 I'm not sure what it would be called but if anyone knows offhand

13:48 justin_smith: so you would want lexically scoped java properties?

13:48 leifw: that would be cool

13:49 though I guess they might not be thread local so that's probably not a thing

13:50 justin_smith: are you using something that needs a property to control its behavior then?

13:51 leifw: yeah

13:51 me.raynes.fs/temp-dir

13:52 justin_smith: leifw: I see an answer for making properties threadlocal

13:52 http://stackoverflow.com/a/9580288/2258453

13:53 leifw: whoa, that's cool

13:53 probably too much machinery for me right now, I'll do something else, but thank you

14:18 ane: does anyone remember a blog post from this year in which there were implementations for some sort of algorithm in various lisp variants (clojure, scheme, racket etc.)

14:18 and you could select them from a handy dropdown on the page

14:19 Temur: ane, this one

14:19 ? http://hyperpolyglot.org/lisp

14:21 ane: no. it was a very bloglike thing

14:32 gfredericks: how to clojure 1) start a repl 2) check twitter while repl starts

14:34 #protip

14:36 delaney: is it just me or is the repl in cursive come up really fast?

14:36 saik0: But if clojure starts fast, when will we lay on our hammoks?

14:37 underplank: hi all. Im using clojure.test and use-fixtures to do setup and tear-down. Is there a way to pass arugments to the test function?

14:37 justin_smith: delaney: it uses some tricks you can use outside cursive

14:37 delaney: https://github.com/technomancy/leiningen/wiki/Faster

14:37 delaney: big ones are trampoline, with fast-trampoline, and not using nrepl

14:37 arrdem: wait you nerds don't have twitter _in_ your repl?

14:38 nREPL over twitter...

14:38 /s

14:38 underplank: this doesnt see to work https://www.refheap.com/100065

14:38 *seem

14:41 brainproxy: in cljs, a (fn ... (recur ...)) boils down to a while loop wrapped in a function, so the recur step doesn't actually call the function again

14:42 is jvm clj, does something similar happen?

14:42 arrdem: (recur) compiles to a GOTO yes

14:43 fn and loop generate labels, and (recur) goes to the most lexically local label with new bindings

14:43 brainproxy: iow, if i can express my function equiv as (fn ... (recur ...) <=> (fn ... (loop ... (recur ...)))

14:44 there's no reason to prefer the latter for perf reasons

14:44 arrdem: correct they are AFAIK strictly equivalent

14:44 brainproxy: thanks

14:44 arrdem: the latter will generate an unused LABEL statement

14:44 but that's fre

14:44 *free

14:45 delaney: justin_smith: yeah i'm very very new to clojure, but watch a lot of videos about it before getting started. i kept waiting for the tooling to be more there, seems to be pretty sweet now.

14:46 i've been ruined by visual studio

14:46 brainproxy: delaney: what? Emacs is the ultimate tooling!

14:46 ;-)

14:46 arrdem: (inc brainproxy) ;; emacs hivemind

14:46 lazybot: ⇒ 5

14:49 * TimMc taps his antennae against arrdem's ("high two, bro!")

14:49 brainproxy: all these parens are yours. use them together. use them in peace

14:51 arrdem: https://www.dropbox.com/s/pyrjccl5q71mmtu/4bb44752-9c0c-4c2d-b826-18d0369bb0b2.gif?dl=0

14:51 ^ emacs user handshake

14:54 brainproxy: nice

14:55 delaney: brainproxy: i went from vim to visual studio. everytime i tried to do anything in emacs my left pinky went on strike claiming cruel work conditions

14:55 arrdem: swapping capslock and control makes all the difference

14:56 delaney: i'm sure with a proper config file emacs is great.

14:56 gfredericks: don't even swap, who needs capslock

14:57 whodidthis: poor capslock, on vim capslock is esc, on emacs control

14:58 cfleming: delaney: Don't listen to the hivemind!

14:58 * arrdem evolves

14:58 * cfleming (is biased though)

14:59 cfleming: arrdem: I'm busy right now, but I owe you a mail about RT, I can do that easily in IntelliJ to try it out

15:00 arrdem: cfleming: copy I was up bloody late hacking on Grim last night so I've spent my f/oss free time for a while no rush

15:01 cfleming: arrdem: Ok cool. I'll take a look when I get a moment - do you have your previous change in a branch somewhere public?

15:02 arrdem: cfleming: https://github.com/ox-lang/clojure if memory serves

15:02 cfleming: arrdem: Ok, will check it out. Mostly wanted a list of the methods to move.

15:03 arrdem: cfleming: that's one approach the the refactor, not the one I'd take were I to do it again but that fork builds and runs code just fine.

15:03 cfleming: arrdem: Yeah, I'm going to try to make a minimal patch to see how small it can get

15:03 arrdem: :+1:

15:04 brainproxy: arrdem: agreed re: capslock

15:04 delaney: maybe take a look at bbatsov's prelude, good setup right out of the box

15:04 cfleming: delaney: If you want a very quick REPL in Cursive to play around with, and you don't need macroexpansion or the test integration, use the clojure.main REPL, starts in a flash.

15:05 brainproxy: gfredericks: actually, that's true; I simply have capslock be another left-ctrl

15:05 arrdem: cfleming: oh here it is https://github.com/ox-lang/lib-clojure

15:06 cfleming: arrdem: Cool, thanks

15:07 gfredericks: brainproxy: yeah remapping your left ctrl to capslock is bound to only ever be used in error

15:08 arrdem: cfleming: nope still the wrong repo. This is it. I checked the history :P https://github.com/arrdem/clojure/tree/arrdem

15:08 I should throw away some of these Clojure forks...

15:13 cfleming: the ox-lang/* repos are dead. the arrdem/ repo is the real one.

15:13 cfleming: arrdem: ok, got it, thanks

15:14 TEttinger: arrdem, what did you do??? who killed ox-lang????

15:14 arrdem: TEttinger: chill brah https://github.com/ox-lang/ox

15:14 TEttinger: hehe

15:14 arrdem: I BOUGHT THE WEBSITE OK

15:14 I'M NOT GOING ANYWHERE

15:14 TEttinger: heh

15:15 arrdem: one day god willing I'll actually be able to hack on it...

15:15 delaney: oh i was just saying cursive's repl startup seemed fine to me

15:15 TEttinger: Made avalable for distribution eh?

15:16 delaney: its just nice to have a repl in general

15:16 TEttinger: is that a pun on vals being static and immutable?

15:16 delaney: though i still certainly don't feel at home compared to js/C#

15:16 arrdem: TEttinger: not consciously

15:16 TEttinger: hehe

15:17 * arrdem closes Clojure tabs, goes back to school work

15:19 TimMc: arrdem: https://s3.amazonaws.com/lowres.cartoonstock.com/animals-shaking_hands-handshakes-secret_handshakes-octopuses-squid-bve0007_low.jpg

15:19 arrdem: (inc TimMc)

15:19 lazybot: ⇒ 96

15:19 arrdem: something something carpal tunnel

15:19 TimMc: Related: http://fc04.deviantart.net/fs71/i/2011/029/8/3/emacs_user_at_work_by_earlcolour-d38aj2x.jpg

15:20 arrdem: https://github.com/jonathanslenders/pyvim okay slackers where's my emacs in clojure

15:21 TEttinger: cfleming: I was wondering how if at all you can get javadoc/clj docstrings to show in intellij

15:22 is there a keybinding for this? some name I should look for?

15:22 puredanger: Press f1?

15:22 arrdem: lol

15:22 TEttinger: puredanger, I'm used to f1 opening a browser in VS, where it displays the docs automatically

15:22 puredanger: No, seriously :)

15:22 TEttinger: oh nice

15:23 gfredericks: didn't somebody have a lib that had enhanced output for clojure.test things? I thought it was jakemcc but can't find anything there

15:23 TEttinger: (as in, if you press f1 on, say, a for loop in C#, it opens up the MSDN docs for "how does i looping")

15:23 gfredericks: the thing I want in particular right now is for ex-data to get printed

15:23 hey speaking of which

15:23 puredanger: There is a ticket for that

15:23 gfredericks: ,(Exception.)

15:24 clojurebot: #error{:cause nil, :via [{:type java.lang.Exception, :message nil, :at [sandbox$eval25 invoke "NO_SOURCE_FILE" -1]}], :trace [[sandbox$eval25 invoke "NO_SOURCE_FILE" -1] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Compiler eval "Compiler.java" 6755] [clojure.core$eval invoke "core.clj" 3079] [clojure.core$eval3$fn__4$fn__14 invoke "NO_SOURCE_FILE" 0] ...]}

15:24 gfredericks: ,(ex-info "Alex's ticket" {:foo 12})

15:24 clojurebot: #error{:cause "Alex's ticket", :via [{:type clojure.lang.ExceptionInfo, :message "Alex's ticket", :at [clojure.core$ex_info invoke "core.clj" 4591]}], :trace [[clojure.core$ex_info invoke "core.clj" 4591] [sandbox$eval49 invoke "NO_SOURCE_FILE" 0] [clojure.lang.Compiler eval "Compiler.java" 6792] [clojure.lang.Compiler eval "Compiler.java" 6755] [clojure.core$eval invoke "core.clj" 3079] ...]}

15:24 gfredericks: puredanger: ^ is the ex-data not present there? should it be?

15:25 (I realize this is separate from clojure.test printing behavior)

15:25 puredanger: Seems like a good idea

15:25 Nothing like that filed

15:25 gfredericks: I can ticket+patch if you like

15:27 puredanger: possible downside: I imagine idiomatically ex-data can be arbitrarily large, and therefore not the best for printing by default

15:29 Bronsa: gfredericks: it used to print it though

15:29 gfredericks: who did when?

15:29 (and what?)

15:29 I have two different topics I'm actively juggling in this conversation

15:29 puredanger: It used to tostring I think

15:29 But no longer does

15:29 Bronsa: ExceptionInfo objects, used to print ex-data in their toString

15:30 gfredericks: we're talking about clojure.test now?

15:30 puredanger: Nope

15:30 Bronsa: no

15:30 gfredericks: dangit

15:30 puredanger: Just exinfo printing

15:30 Bronsa: &*clojure-version*

15:30 lazybot: ⇒ {:major 1, :minor 7, :incremental 0, :qualifier "alpha1"}

15:30 Bronsa: &(ex-info "foo" {:bar 1})

15:30 lazybot: ⇒ #<ExceptionInfo clojure.lang.ExceptionInfo: foo {:bar 1}>

15:31 puredanger: Ticket welcome :)

15:31 gfredericks: oh I see, so my possible downside has been active in 1.6 this whole time is what you're saying

15:31 Bronsa: yup

15:31 gfredericks: ACK to you both

15:31 I'll do a ticket thing later today

15:31 puredanger: Thx

16:36 cfleming: TEttinger: https://cursiveclojure.com/userguide/documentation.html

16:37 TEttinger: don't mean to RTFM you but, well, it's all there :-)

16:37 TEttinger: hehe

16:38 sveri: TEttinger CTRL + Shift + A is a pretty useful command in intellij, you can find most of the things you need there

16:38 TEttinger: huh, I don't see f1 there

16:39 sveri: Yea, but if you type documentation you will find "quick documentation" and it's shortcut

16:39 not sure if that is enough

16:40 TEttinger: no it's enough

16:40 puredanger mentioned f1 but I don't see it in cursive docs, specifically

16:41 i guess it may be open manual... another rtfm :)

16:41 cfleming: TEttinger: Looks like F1 does work, I always use Ctrl-J

16:41 TEttinger: ok

16:41 cfleming: TEttinger: I don't use the F-keys much for things I use a lot, too far away

16:41 TEttinger: Or Ctrl-P on Win/Linux I think it is

16:42 TEttinger: yah, agreed. this could be tricky to get used to because I switch so often from VS to IntelliJ now

16:42 (two simultaneous projects, 3 languages)

16:42 sveri: ah, context switches, expensive! :D

16:43 cfleming: TEttinger: Ok, if F1 works in both then that's probably your best option, or you can remap in one or the other of course

16:43 sveri: TEttinger there is also a keymap option called "Visual Studio" maybe that's ok for you

16:44 TEttinger: haha wunderbar

17:03 bbloom_: delaney: just edit text in vim and switch to VS to click around and use resharper w/ the mouse

18:00 lodin: Why is there an explicit check "disabling" redefinition in defmulti? Is that a feature that can be relied upon when writing macros that emit defmultis?

18:02 gfredericks: lodin: I assume it's to prevent redefinition of the dispatch function, which could put existing defmethods in a weird state

18:02 none of this global-extension-point stuff is very good with reloading :/

18:04 lodin: gfredericks: I assume so too, but why check against it? Is there a legitimate use case for emitting several defmultis?

18:04 gfredericks: I figured it had more to do with reloading than with having several of them in a file

18:04 those two are indistinguishable in a lot of contexts

18:04 lodin: Yes, I see your point.

18:10 gfredericks: I assume that it is unsafe to rely on this feature from inside the program then, since it's for tooling.

18:11 gfredericks: lodin: so what are you up to?

18:11 lodin: gfredericks: Just writing some convenience macros.

18:12 gfredericks: lodin: and why might they defmulti multiple times?

18:14 lodin: gfredericks: Because I emit a multimethod, and if the defmulti doesn't exist I should create it, and if it does exist I should only emit the defmethod and extend the multi.

18:15 gfredericks: what does the macro do?

18:16 lodin: gfredericks: Don't make me try to explain it in just a few lines on irc. :-)

18:20 gfredericks: okay then I can't figure out the value judgments you were asking about

18:21 everything you've said so far is weird enough that I can't extrapolate or ignore details

18:21 lodin: :-)

18:34 alexbaranosky99: anyone out there using leiningen's checkouts feature? I thought all I had to do was create a /checkouts dir, then add symlinks to the local source inside it

18:35 but when I do that and run the tests, I get an error message like: "no such var: lib-in-checkouts/my-var"

18:36 gfredericks: alexbaranosky99: you still have the lib declared in the deps?

18:36 alexbaranosky99: gfredericks: yeah, I just took a working project that was pulling from an internal maen repo, and added the /checkouts folder

18:36 gfredericks: I wonder if it is a lein version issue?

18:37 gfredericks: alexbaranosky99: does that var exist in the not-checked-out version?

18:37 alexbaranosky99: I'm on leiningen 2.5.0

18:37 gfredericks: and does the lib have an unusual source path?

18:37 (hopefully that last one doesn't actually cause a problem but who knows)

18:38 alexbaranosky99: gfredericks: I checked the soruce code -- the var is in there

18:38 gfredericks: alexbaranosky99: I mean in the version you have declared specifically, not the checkouts version

18:38 alexbaranosky99: gfredericks: by unusual source path do you just mean the project structure of the source? IT's pretty standard leiningen template

18:38 gfredericks: yeah that's all I meant

18:38 I don't know how checkouts works exactly so if it just adds /checkouts/foo/src to your path that would break easily

18:39 alexbaranosky99: gfredericks: I think I have a sound hypothesis going now

18:40 the classpath is picking up an old version of that jar... that doesn't have the var in question

18:40 because that jar is on the resource path

18:40 ok I think that'll fix it let me see

18:40 whodidthis: needs to also be a -SNAPSHOT and installed to m2

18:41 gfredericks: oh yeah I should have asked about `lein classpath` first

19:03 oh wow I didn't realize clojure now goes out of its way to pretty-print throwables (as data)

19:04 bbloom_: gfredericks: yeah, nobody made a big deal about it, but it's awesome

19:04 gfredericks: puredanger: opinions about key name? :data, :ex-data, :things

19:04 bbloom_: took me a minute to realize it wasn't my normally-pretty-printing repl

19:05 bbloom_: gfredericks: you rocking whidbey/pudget? :-)

19:05 puredanger: you can also use the new Throwable->map function to get it as data too

19:05 gfredericks: bbloom_: yeah

19:06 the worst part about new clojure stuff is you can't go put it in your libs right away because of compatibility

19:06 puredanger: gfredericks: dunno, I'd probably be overruled regardless :)

19:06 gfredericks: I keep wanting to make a lib just for throwing new clojure features in when possible

19:07 puredanger: :data seems ok

19:08 I found it hugely annoying that due to dependency issues, I could not just leverage (pprint (Throwable->map ex)) in the print-method :)

19:08 gfredericks: ack ack

19:08 puredanger: huh? print-throwable does call Throwable->map

19:08 oh wait

19:08 you mean clojure.pprint/pprint

19:08 righto

19:09 puredanger: yeah, had to rebuild a bad version of map printing

19:09 gfredericks: these are exciting times we live in

19:10 haha I changed :message to :massage in the printing code and the tests passed

19:11 puredanger: there aren't any tests for that printing format

19:11 gfredericks: I'll probably make some :)

19:11 puredanger: so tedious with all the line numbers and giant strings etc

19:11 if you make some that don't suck, I'd love to have them

19:11 gfredericks: you could test a roundtrip pretty easily right?

19:12 puredanger: well... maybe

19:12 gfredericks: (= (Throwable->map ex) (read-string (print-string ex)))

19:12 puredanger: except there is no reader for #error

19:12 gfredericks: right okay so handwave that in there too

19:12 puredanger: if you make it, I'll take it :)

19:13 gfredericks: hey guys I just got a blank check to put new things in clojure

19:13 puredanger: definitely a lot of things written on that check :)

19:14 someone else has to sign it too

19:15 brucehauman: gfredericks: I’ll sign it

19:15 gfredericks: sweet we're in business

19:16 brucehauman: lol

19:16 gfredericks: first thing is we implement that one ticket to make colons whitespace in map literals so we can all write json

19:17 brucehauman: I’m totally not signing that crap

19:17 :)

19:17 thats not even funny

19:18 gfredericks: also effective immediately I will take any patch whatsoever for $100,000 each

19:18 brucehauman: :)

19:20 puredanger: Ugh that ticket. Been trying to work up the nerve to close that for years :)

19:21 gfredericks: lol

19:23 I'm gonna add a ticket for making whitespace be not whitespace so we can write python

19:24 brucehauman: gfredericks: i didn’t realize your ambitions went so far beyond swerjure

19:25 gfredericks: I will call it snakejure

19:26 brucehauman: so the code is animated and you have to box it in to beable to edit it, I get it

19:37 TimMc: only commas for whitespace

19:38 gfredericks: ' ' aliases '(' and '\n' aliases ')'

19:38 feel free to use all four

19:38 TimMc: Instead of ))))))) you get a big blank area.

19:39 gfredericks: finally, lisp is solved

19:39 brucehauman: i can’t believe how easy that was

19:52 Code_Monk: Hi Everyone, hope all is well! can anyone kindly tell me how to set a default value for a hash-map using fnil, I couldnt get it right.

19:53 its two level deep map e.g: {:A {:B 4, :C 3} :B {:A 2} .....} something like that.

19:57 justin_smith: Code_Monk: do you want a default on lookup, a default when adding to some nested structure, a default on creation?

19:57 fnil is usually seen when adding to a nested data structure in multiple steps

19:58 Code_Monk: I'm looking for a default on lookup, it doesnt necessarily have to use fnil.

19:59 justin_smith: ,(reduce (fn [m k] (update-in m [k] (fnil inc 0))) {} [1 2 3 1 2 1])

19:59 clojurebot: {1 3, 2 2, 3 1}

19:59 justin_smith: ,(get-in {:a {:b {:c nil}}} [:a :b :c] 42)

19:59 clojurebot: nil

19:59 justin_smith: err...

19:59 ,(doc get-in)

19:59 clojurebot: "([m ks] [m ks not-found]); Returns the value in a nested associative structure, where ks is a sequence of keys. Returns nil if the key is not present, or the not-found value if supplied."

19:59 justin_smith: aha

19:59 ,(get-in {:a {:b {:c nil}}} [:a :b :c :d] 42)

19:59 clojurebot: 42

20:01 Code_Monk: great! thanks guys. I appreciate it!

20:02 justin_smith: Code_Monk: fnil provides an alternate argument to a function if the input is nil, but get-in, get, etc. all take a default arg

20:19 seangrove: What's the expected way to use tools.analyzer to analyze a file on disk without loading/evaling it?

20:19 Combine with tools.reader?

20:23 lodin: Bug?

20:23 ,(defprotocol P (p [x])) (def p' (comp identity p)) (defrecord R []) (extend-type R P (p [_] :R)) (p (R.)) (p' (R.))

20:23 clojurebot: P

20:23 seangrove: And is there an easy way to read in an entire clojure source file with tools.reader?

20:23 ambrosebs: ^^

20:23 lodin: Err. Didn't show what I wanted.

20:23 On my 1.6.0 the last form with p' fails.

20:24 justin_smith: lodin: you need a do if you want separate forms on one line to run with the bots

20:24 lodin: If I contract defrecord and extend-type then it works.

20:24 ,(do (defprotocol P (p [x])) (def p' (comp identity p)) (defrecord R []) (extend-type R P (p [_] :R)) (p (R.)) (p' (R.)))

20:24 clojurebot: #error{:cause "No implementation of method: :p of protocol: #'sandbox/P found for class: sandbox.R", :via [{:type java.lang.IllegalArgumentException, :message "No implementation of method: :p of protocol: #'sandbox/P found for class: sandbox.R", :at [clojure.core$_cache_protocol_fn invoke "core_deftype.clj" 554]}], :trace [[clojure.core$_cache_protocol_fn invoke "core_deftype.clj" 554] [sandbox$ev...

20:24 lodin: justin_smith: Thanks.

20:25 ,(do (defprotocol P (p [x])) (def p' (comp identity p)) (defrecord R [] R P (p [_] :R)) (p (R.)) (p' (R.)))

20:25 clojurebot: #error{:cause "only interfaces are supported, had: sandbox.R", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.IllegalArgumentException: only interfaces are supported, had: sandbox.R, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6740]} {:type java.lang.IllegalArgumentException, :message "only interfaces are supported, had: sandbox...

20:25 lodin: ,(do (defprotocol P (p [x])) (def p' (comp identity p)) (defrecord R [] P (p [_] :R)) (p (R.)) (p' (R.)))

20:25 clojurebot: :R

20:25 lodin: ,(do (defprotocol P (p [x])) (defn p' [x] (identity (p x))) (defrecord R []) (extend-type R P (p [_] :R)) (p (R.)) (p' (R.)))

20:25 clojurebot: :R

20:25 lodin: But the first fails. :-/

20:28 I.e., it fails if I deref #'p before I do extend-type.

20:40 seangrove: "Cannot recur across try" - grr, guess I'll just reach for some state then.

20:42 amalloy: lodin: if you capture the value of a protocol function, rather than its var, it doesn't get updated

20:44 gfredericks: seangrove: I think I tried to make a lib that would make that easier

20:44 it might have been shoddy though

20:45 seangrove: Is there a reader that knows how to create ISeq from itself?

20:45 gfredericks: Just surprised at how imperative this stuff is, I suppose

20:45 gfredericks: yeah it was this https://github.com/gfredericks/referee

20:45 I think I immediately regretted it but can't remember why

20:46 seangrove: Heh, looks interesting though

20:46 gfredericks: I guess it probably works

20:50 lodin: amalloy: Yes, I noticed. :-)

20:51 amalloy: It a different behavior from multimethods though, since defmethod doesn't update the var.

20:58 gfredericks: oh snap should it include the ex-data of all the causes or only the root cause

21:15 seangrove: Is it not possible to rewind a reader? I'm trying to use tools.reader, but I want to know if there's more to read without consuming the next form

21:21 justin_smith: seangrove: in fact this is what the "PushBack" in PushBackReader is named for

21:22 seangrove: justin_smith: Ah, makes sense

21:22 justin_smith: seangrove: it supports mark and reset

21:23 seangrove: oh wait, it supports calling mark, but doesn't actually support marking, weird

21:23 seangrove: justin_smith: any idea why raising an exception is such a popular way of expressing EOF? I'm not sure I really understand the benefit to this approach

21:24 justin_smith: seangrove: if you are eg. reading a byte, you need some value that is not a byte to indicate the stream is empty. So either you have try/catch or a conditional after your read based on type

21:25 I imagine this gets messy with primitive values too

21:26 all that said, an interface that does one thing for a successful read and another for EOF would seem to be the better and unprovided 3rd option

21:26 gfredericks: is that why the InputStream class uses int instead of byte?

21:27 justin_smith: gfredericks: could be - also it allows pretending we can do unsigned bytes

21:27 gfredericks: I like to pretend!!

21:29 thatguy: Using compojure/ring. is there an idiom for requiring authentication for part of a site, i.e. anything with /admin in the url?

21:29 justin_smith: thatguy: sure, a middleware that wraps that subtree

21:29 thatguy: or you just call the same if statement function around all the handler methods?

21:30 yeah, middleware seemed like a good idea, just never made one yet. think something like that exists?

21:30 otherwise it'd be good simple one to start with I'd guess

21:31 justin_smith: (defn my-middleware [handler] (fn [request] something something handler request something))

21:31 typically you end up calling the handler, maybe you alter the request or do something with the value returned by the value returned by calling the handler on the request

21:32 thatguy: ok. seems easy enough. Think something like Friend would work? probably more than i need right now, but i guess they have their own middleware. thx

21:32 justin_smith: s/the value returned by the value returned/the value returned/

21:32 yes, friend has its own middleware

21:33 where you plug in your auth stuff

21:37 gfredericks: ha just had my first bug where I accidentally called map with 1 arg

21:38 will we ever get to the point where transducers aren't primarily used by accident?

21:46 woah; my cider repl switched to always returning one result from any eval

21:46 rather than N

21:46 so "" evals to nil and "1 2" evals to 2

21:49 TimMc: (do %)

21:49 (do ~@stuff) rather

21:50 gfredericks: ,(do)

21:50 clojurebot: nil

21:50 gfredericks: hrmph.

21:50 as a fuddy-duddy, I object to this change.

21:51 TimMc: map should also take zero arguments and randomly return one of nil, a string, or an integer.

21:51 This will make debugging more entertaining.

21:54 gfredericks: ~as |a fuddy duddy,| I object to this change.

21:54 clojurebot: Ok.

21:54 gfredericks: ~hrmph ||

21:54 clojurebot: Cool story bro.

21:55 gfredericks: ~|| hrmph

21:55 clojurebot: Titim gan éirí ort.

21:55 seangrove: Can core.match match against lists? I'm not seeing any examples on the wiki

21:58 I guess this kind of handles it http://dev.clojure.org/jira/browse/MATCH-103

22:04 Seems like it isn't possible to match against nested lists, though? https://www.refheap.com/100081

22:07 thatguy: still there justin_smith?

22:13 well.. this is my best at an authorization middleware: any glaring flaws?

22:13 (defn auth-required [handler]

22:13 (fn [req]

22:13 (if (and (not (authorized? req))

22:13 (.startsWith (:uri req) "/mgr"))

22:13 (redirect "/enter")

22:13 (handler req))))

22:16 seangrove: thatguy: Might want to make "/mgr" a vector so you can add a few different prefixes. Nicer to grow into

22:16 e.g. (and (not (authorized? req)) (some #(.startsWith (:uri req)) ["/mgr" "/admin"]))

22:17 thatguy: ha, was just about to ask, now i know about "some". thx

22:17 lasergoat: probably need a % in there

22:17 seangrove: thatguy: What lasergoat said, heh

22:20 thatguy: thx for the help. guess i should be in #clojure-beginners

22:20 seangrove: thatguy: I think that kind of question is fine for #clojure

22:21 Not an op though

22:34 mischov: thatguy: https://www.refheap.com/ is a good place to put code samples you want to show

22:40 thatguy: https://www.refheap.com/100082 thx mischov. Glad to support clojure sites :)

22:57 mischov: thatguy: Updated with Sean's answer. https://www.refheap.com/100083

Logging service provided by n01se.net