2015-03-19
| 00:00 | devn | i didn't find it, just wanted to share the knowledge |
| 00:15 | amalloy | devn: what is the bug? |
| 01:04 | justin_smith | amalloy: ##(= (partition-all 9/4 (range 10)) (partition-all (long 9/4) (range 10))) |
| 01:04 | lazybot | ⇒ false |
| 01:04 | amalloy | well yeah. (not= 9/4 (long 9/4)) |
| 01:04 | amalloy | if you pass different arguments to a function, and get different results back, that is not evidence of a bug |
| 01:05 | justin_smith | my interpretation of that is that partition treats a rational different than long would |
| 01:05 | amalloy | IMO the bug is that it doesn't crash when you pass 9/4 |
| 01:05 | amalloy | if there's any bug at all |
| 01:05 | justin_smith | heh, fair enough |
| 04:27 | Glenjamin | ,(long 9/4) |
| 04:27 | clojurebot | 2 |
| 04:31 | code-shoily | Hello guys |
| 04:35 | code-shoily | having an autoload issue with Luminus with +http-kit |
| 04:36 | code-shoily | Whenever I add a new route, it doesn't work unless I reload the server |
| 04:39 | gyim | the problem is probably that you do something like this: (compojure.handler/site myroutes) |
| 04:39 | gyim | instead you should write (compojure.handler/site #'myroutes) |
| 04:42 | gyim | because if you write (some-fn some-var), the actual value of the var is read and passed to the function. So if the function stores it, it will use the same value even if you redefine the var later |
| 04:42 | gyim | one way to resolve this is to pass the var instead of the actual value |
| 04:45 | code-shoily | isn't the wrap-reload supposed to recompile the folders it is warching? |
| 04:45 | code-shoily | It is not even triggering a reload when I add new handlers, since it is a change in the folder, it should have. Whereas if I change the content of the function, it reloads them fine. |
| 04:51 | gyim | are you sure it does not reload the namespace? My guess is that it does reload it, but the http handler / route object is cached |
| 04:52 | code-shoily | Yes I think what you are saying is right. My bad. |
| 04:57 | code-shoily | Thanks gyim ... it worked now that I have user (-> (routes #'admin-route #'forum-route)) etc.. it was autogenerated from luminus template so didn't care to look into that. I understand it now :) |
| 04:57 | gyim | great! i'm glad it works |
| 05:39 | acron^ | How do I pass in keyword arguments to a function? |
| 06:12 | egli | acron^: a quick google search gives some pretty good hints |
| 06:12 | acron^ | i figured it out in the end =] |
| 06:13 | egli | acron^: http://stackoverflow.com/a/3969693 seems pretty reasonable |
| 06:22 | kungi | How would one start to analyze this exception? |
| 06:22 | kungi | Caused by: java.lang.RuntimeException: No such var: s/defn, compiling:(schema/coerce.clj:25:1) |
| 06:23 | schmir | kungi: ask on irc? |
| 06:24 | schmir | sorry couldn't resist :) |
| 06:24 | kungi | schmir: :-P |
| 06:24 | schmir | can't you take a look at the source? |
| 06:25 | kungi | schmir: I did have a look and s/defn is defined. The problem is in this case that it works in one project but does not in another. |
| 06:26 | TEttinger | maybe s hasn't been required in yet? |
| 06:26 | schmir | different dependencies? |
| 06:26 | TEttinger | or it's requiring an old version? |
| 06:26 | TEttinger | lein clean |
| 06:26 | kungi | I will start with lein clean first thanks. |
| 06:28 | kungi | \o/ |
| 06:28 | kungi | (inc TEttinger) |
| 06:28 | lazybot | ⇒ 44 |
| 06:28 | TEttinger | woah thanks! |
| 06:28 | TEttinger | surprised that was all it needed! |
| 06:29 | TEttinger | glad too |
| 06:29 | kungi | Remember: If something strange happens you can't explain => lein clean |
| 06:29 | kungi | Strange as in some error in library code that works elsewhere |
| 06:29 | schmir | kungi: or use boot (we met on clojured btw) |
| 06:31 | kungi | schmir: then you should join #clojure.de the german clojure channel! |
| 06:31 | schmir | ok |
| 06:46 | noncom | what's the best clojure way to work with zip files? |
| 06:46 | schmir | noncom: I've used java.util.zip |
| 06:46 | kungi | noncom: I use java.util.zip for this |
| 06:47 | schmir | not sure if that's the best way |
| 06:47 | kungi | :-) |
| 06:47 | noncom | :) |
| 09:00 | Retsamtip | apologies for cross-posting. am having trouble setting cookies in a Ring app (Luminus) |
| 09:25 | noncom|2 | ,(def k 1) |
| 09:25 | clojurebot | #'sandbox/k |
| 09:25 | noncom|2 | ,(meta k) |
| 09:25 | clojurebot | nil |
| 09:25 | noncom|2 | ,(reset-meta! k {:z 1}) |
| 09:25 | clojurebot | #error{:cause "java.lang.Long cannot be cast to clojure.lang.IReference", :via [{:type java.lang.ClassCastException, :message "java.lang.Long cannot be cast to clojure.lang.IReference", :at [clojure.core$reset_meta_BANG_ invoke "core.clj" 2287]}], :trace [[clojure.core$reset_meta_BANG_ invoke "core.clj" 2287] [sandbox$eval71 invoke "NO_SOURCE_FILE" -1] [clojure.lang.Compiler eval "Compiler.java" 6... |
| 09:25 | noncom|2 | ,(reset-meta! #'k {:z 1}) |
| 09:25 | clojurebot | {:z 1} |
| 09:25 | noncom|2 | ,(meta k) |
| 09:25 | clojurebot | nil |
| 09:25 | noncom|2 | ^^^^^ how is that? why nil ? |
| 09:25 | agarman | ,(meta #'k) |
| 09:25 | clojurebot | {:z 1} |
| 09:26 | noncom|2 | wow |
| 09:26 | noncom|2 | should i always #' with meta? |
| 09:26 | agarman | meta is on Var |
| 09:26 | agarman | ,(def z {}) |
| 09:26 | clojurebot | #'sandbox/z |
| 09:26 | noncom|2 | aah, right.. |
| 09:26 | noncom|2 | got it |
| 09:26 | agarman | ,(reset-meta #'z {:foo 1}) |
| 09:26 | clojurebot | #error{:cause "Unable to resolve symbol: reset-meta in this context", :via [{:type clojure.lang.Compiler$CompilerException, :message "java.lang.RuntimeException: Unable to resolve symbol: reset-meta in this context, compiling:(NO_SOURCE_PATH:0:0)", :at [clojure.lang.Compiler analyze "Compiler.java" 6535]} {:type java.lang.RuntimeException, :message "Unable to resolve symbol: reset-meta in this con... |
| 09:27 | agarman | ,(reset-meta! #'z {:foo 1}) |
| 09:27 | clojurebot | {:foo 1} |
| 09:27 | agarman | ,(meta z) |
| 09:27 | clojurebot | nil |
| 09:28 | agarman | noncom|2: meta is on a Var, in (meta k), k gets resolved and isn't a Var |
| 09:28 | agarman | evaled |
| 09:28 | noncom|2 | so it takes meta on 1? (the k's value).. |
| 09:28 | noncom|2 | ,(meta 1) |
| 09:28 | clojurebot | nil |
| 09:28 | noncom|2 | right |
| 09:28 | agarman | yes |
| 09:29 | noncom|2 | umm.. is it possible to somehow make (meta) return not nil on (meta 1) ? |
| 09:29 | agarman | meta is just a function so it gets evaled like any other function |
| 09:30 | agarman | 1 isn't a IReference so it can't have meta attached to it |
| 09:30 | noncom|2 | why no exception then? |
| 09:30 | noncom|2 | i think this worth a class cast one |
| 09:30 | agarman | ,(source meta) |
| 09:30 | clojurebot | Source not found\n |
| 09:31 | agarman | because meta returns nil if what you're passing it isn't instance? clojure.lang.IMeta |
| 09:31 | noncom|2 | ah, ok.. |
| 09:32 | agarman | ,(defn mmeta [x] (if (instance? clojure.lang.IMeta x) (.meta x))) |
| 09:32 | clojurebot | #'sandbox/mmeta |
| 09:32 | agarman | ,(mmeta 1) |
| 09:32 | clojurebot | nil |
| 09:32 | agarman | ,(mmeta #'k) |
| 09:32 | clojurebot | {:z 1} |
| 09:32 | noncom|2 | so they wanted no exception here |
| 09:33 | noncom|2 | is there a way to imitate #' with a passed symbol? |
| 09:33 | noncom|2 | like 'sym can be imitated with (quote sym) |
| 09:33 | agarman | ,(var k) |
| 09:33 | clojurebot | #'sandbox/k |
| 09:34 | noncom|2 | so, this is very good |
| 09:35 | agarman | http://java.ociweb.com/mark/clojure/images/ClassDiagram.png |
| 09:35 | agarman | that's a useful diagram for understanding relationships of Clojure's various cell types. |
| 09:37 | noncom|2 | thank you, it is a very useful one |
| 10:40 | borkdude | when I serve a file from clojure ( liberator), how so I set the name properly? |
| 10:41 | mpenet | via the Content-Disposition header if I recall |
| 10:41 | schmir | right. or redirect to url with the right name as last component |
| 10:42 | borkdude | mpenet schmir thanks :) |
| 10:42 | ordnungswidrig | borkdude: Add a content-disposition header, you need to use ring-response for that. |
| 10:43 | ordnungswidrig | schmir: that only works if the the content cannot be displayed by the browser. |
| 10:43 | borkdude | ordnungswidrig how do I add a header with liberator? with :as-response? |
| 10:43 | borkdude | ordnungswidrig like at the bottom here? https://clojure-liberator.github.io/liberator/doc/representations.html |
| 10:44 | ordnungswidrig | borkdude: no, that would add a header for every response of that resource, i.e. for 404s, too. |
| 10:44 | borkdude | ordnungswidrig hmm right |
| 10:45 | borkdude | ordnungswidrig I have been puzzled by how to manipulate the ring response in liberator. how do I do that in general |
| 10:46 | ordnungswidrig | borkdude: in :handle-ok (fn [ctx] (ring-response (assoc-in (as-response ctx {:foo :my-data}) [:headers "Content-Disposition"] "attached; filename=foo.txt"))) |
| 10:47 | michaelr` | I have this ":hooks [leiningen.cljsbuild] |
| 10:47 | borkdude | ordnungswidrig so if I return a map in the function, liberator interprets it as a ring response? |
| 10:47 | ordnungswidrig | borkdude: only if you wrap the map with `ring-response` |
| 10:47 | michaelr` | I have this ":hooks [leiningen.cljsbuild]" in my prod profile but uberjar doesn't run cljsbuild - why? |
| 10:48 | ordnungswidrig | In 0.12.3 ring-response will support that directly: (ring-response my-data-for-as-response {:headers {"Foo" "bar"}}) |
| 10:49 | ordnungswidrig | You can then specify a second parameter to ring-respose which is a ring-response map which is combined with the response generated by as-response for the first parameter |
| 10:49 | borkdude | ordnungswidrig ah I get it now. ring-response is a function from liberator. doh, sorry :) |
| 10:49 | borkdude | ordnungswidrig thanks |
| 10:50 | borkdude | ordnungswidrig thank you for liberator btw <3 <3 <3 |
| 10:50 | ordnungswidrig | borkdude: it's a please to see people use it. |
| 10:51 | ordnungswidrig | pleasure... |
| 11:00 | borkdude | ordnungswidrig thanks it worked. the order of args in as-response had to be {:foo :my-data} ctx btw. |
| 11:01 | ordnungswidrig | borkdude: ah, sure. |
| 11:01 | ordnungswidrig | sorry. |
| 11:01 | borkdude | ordnungswidrig no problem |
| 11:07 | borkdude | dnolen are functions that are referred in the ns form, but not actually used, also pruned by closure, or not? |
| 11:10 | yogsototh | Hi, I experience a strange behaviour with threads. I do a (future (while true...)) but my thread get killed or maybe is blocked |
| 11:10 | yogsototh | Generally the thread stop working when I use a lot of other threads intensively |
| 11:10 | borkdude | dnolen sorry I should have asked this in #clojurescript |
| 11:11 | dnolen | borkdude: dead code elimination doesn't have anything to do with ns forms, :refers are really complete fiction for var resolution |
| 11:11 | borkdude | dnolen ok, so no worries there then |
| 11:32 | sm0ke | in reagent are there functions to work with `ref` attributes? |
| 11:50 | danlentz | i noticed the const macro in im.chit/hara library: https://github.com/zcaudate/hara/blob/master/src/hara/expression/compile.clj#L3 |
| 11:51 | danlentz | would it be considered bad form in clojure to effect compile-time evaluation with something like: `~(+ 1 1) |
| 11:52 | danlentz | ie, rather than (defmacro const [body] (eval body)) |
| 11:52 | danlentz | (const (+ 1 1)) |
| 12:07 | gfredericks | danlentz: I'm not sure why `~(+ 1 1) would do what you want |
| 12:08 | danlentz | yes, i think i had a brain fart. thanks |
| 12:13 | danlentz | so, could this be accompished with a data-readers.clj — to implment an #eval reader tag that would be equivalet to common lisp #. |
| 12:13 | danlentz | ? |
| 12:18 | gfredericks | yep; you have to be careful with that stuff since the local scope is irrelevant when using eval |
| 12:18 | gfredericks | I think (def ^:const ...) is usually just as good |
| 12:20 | mfikes_ | danlentz: Dang... I tried what you were doing in ClojureScript with Closure optimizations and (+ 1 1) gets reduced down to 2. |
| 12:21 | danlentz | just looking for the most ideomatic way to manually cause partial evaluation of a piece of a computation at compile time |
| 12:21 | danlentz | right |
| 12:22 | danlentz | i could just replace the code with the evaluated constant, but I was looking to keep some of the trivial computations for the sake of documentation value (as opposed to weird constants showing up all over the place) |
| 12:23 | gfredericks | danlentz: why not just a def? |
| 12:23 | gfredericks | (def TAU (* 2 Math/PI)) |
| 12:24 | danlentz | there are a lot of them |
| 12:24 | danlentz | about 20 i guess |
| 12:24 | gfredericks | and you don't like lots of defs? |
| 12:25 | danlentz | situation such as this: |
| 12:25 | danlentz | https://github.com/danlentz/clj-uuid/blob/master/src/clj_uuid.clj#L591 |
| 12:25 | justin_smith | danlentz: if you really need compile time evaluation, use a macro and suck up the parens, I'd say |
| 12:26 | danlentz | :) |
| 12:26 | justin_smith | well, that is for compile time eval plus no runtime deref |
| 12:27 | justin_smith | another hack is to put your top level code inside a let block (but that's ugly and wrong) |
| 12:27 | gfredericks | justin_smith: why not just ^:const? |
| 12:27 | danlentz | its not a huge big deal calliing (mask 2 62) is just a few bit-level operations |
| 12:27 | justin_smith | gfredericks: I'm confused by :const, maybe it does the right thing? |
| 12:27 | danlentz | Already generating UUID’s 10x faster than java.util.UUID :) |
| 12:28 | AeroNotix | I've always wondered what use-case you need to be generating UUIDs really quickly. |
| 12:28 | gfredericks | justin_smith: yeah I think it's exactly what he's asking for |
| 12:28 | danlentz | The intent of the UUID is to enable distributed systems to uniquely identify information without significant central coordination |
| 12:29 | AeroNotix | and? |
| 12:29 | danlentz | http://danlentz.github.io/clj-uuid/ |
| 12:29 | gfredericks | justin_smith: it gets the value embedded in the bytecode, bypassing the var |
| 12:30 | danlentz | talks a bit about UUID’s |
| 12:30 | justin_smith | gfredericks: that's the right answer then, yeah |
| 12:30 | AeroNotix | danlentz: I've read it -- you just say "It's better because it's faster" |
| 12:30 | danlentz | i’m not explaining all the ways to use UUID’s there |
| 12:30 | danlentz | i think that is like explaing all the ways to use memory addresses |
| 12:31 | AeroNotix | I'm just curious why you need to have incredibly faster generation of UUIDs. |
| 12:31 | justin_smith | danlentz: I think he's asking for a use case where UUID generation would be the bottleneck |
| 12:31 | AeroNotix | yeah this |
| 12:31 | danlentz | it is better because it is compliant with the IETF standard and because it allows you to use UUID’s in a variety of ways that they are intended to be used that were not previously an option |
| 12:32 | danlentz | and it is much much faster if you use v1 ID’s as intended when performance is an issue |
| 12:32 | AeroNotix | so why is the key-feature whenever you mention it, the speed? |
| 12:32 | danlentz | well, because I worked hard to optimize the v1's |
| 12:32 | AeroNotix | danlentz: do you have/did you have a place where uuid generation was a bottleneck? |
| 12:32 | danlentz | thats what they are for: to be fast |
| 12:33 | AeroNotix | UUIDs are used in a lot of places nowadays but I've never heard someone say "dang I wish our UUID generator was faster" |
| 12:33 | AeroNotix | just curious if you had this problem |
| 12:33 | danlentz | given that v3,v5 wasnt available at all (apparently) as a clojure library I didnt think i had to talk a lot about why you might want to use it instead of another namespaced identifier. For V!’s I felt it was important to distinguish their use case. |
| 12:34 | danlentz | yes absolutely |
| 12:34 | AeroNotix | what was your use-case for the speed? |
| 12:34 | danlentz | i wrote it because UUID generation was a bottleneck for implementing various things on a graph database |
| 12:35 | AeroNotix | gotcha, cool. Just the first time I've heard of generating uuids as being the bottleneck |
| 12:35 | tyson2 | Dan, which graph db are you using? |
| 12:35 | danlentz | as an efficent index type for my weight balanced tree collection, which in turn is used for graph indees |
| 12:35 | tyson2 | ah it looks like you're building your own |
| 12:35 | danlentz | well, professionally i use datomic |
| 12:35 | danlentz | but https://github.com/danlentz/clj-fgl |
| 12:35 | danlentz | my own experimental sandbox |
| 12:36 | AeroNotix | https://github.com/danlentz/clj-fgl#tuple-store formatting screwed |
| 12:36 | tyson2 | ok. I'm about to test out a demo of neo4j-clojure |
| 12:36 | danlentz | yeah, its not done |
| 12:36 | justin_smith | tyson2: neo4j has weird ass licensing |
| 12:36 | danlentz | its just a plaything, but ive been working the ideas for a while… |
| 12:37 | justin_smith | tyson2: technically it's the same as eg. mongodb but they enforce it differently... |
| 12:37 | tyson2 | justin, tell me about it. The community version also has some limitations. The commercial version is quite expensive |
| 12:38 | justin_smith | cool, just wanted to make sure you were aware before building anything significant with it and finding yourself potentially stuck |
| 12:38 | tyson2 | but we are semi-committed to neo4j, so I am going to see how it works in a clojure environment |
| 12:42 | danlentz | Aeronotix: Also, I found I got mostly yawns and crickets when I told people I implemented RFC4122 compliant unique identifiers. It seems like it gets poeple to at least look at the site when I say they’re faster, and hopefully from there it also shows some of the other ways UUID’s can be useful. |
| 12:43 | AeroNotix | danlentz: I understand what you mean, but it really perplexed me that someone would take the time to generate UUIDs faster |
| 12:43 | AeroNotix | just was interested |
| 12:43 | AeroNotix | :) |
| 12:44 | danlentz | it actually nauseates me a bit to “promote” my own library, but since I started it’s gotten an order of magnitude more attention and a lot of people have come back with really good suggestions. So, getting it more exposure is helping me to make it better. |
| 12:46 | danlentz | And there have been some really nice reports that have come back that people have seen significant improvement in their productiion code by simply swapping in clj-uuid for UUID generation. |
| 12:47 | danlentz | So, a lot of people think of UUID’s as trivial, but there is a lot to be said for doing them well. |
| 12:47 | AeroNotix | what kind of improvements? |
| 12:47 | danlentz | I don’t have any specific details to share, I’m just going from some of the conversations from the “issues” log |
| 12:48 | danlentz | but for my case, my entire bottleneck was UUID’s so my improvement was 1000% |
| 12:49 | danlentz | for functional, immutable data structures, UUID’s make a very useful addressing token. |
| 12:49 | AeroNotix | cool |
| 12:50 | danlentz | Thefore, if you need to frequently update a functional data structure, the cost of computing new identifiers can mount considerably |
| 12:50 | danlentz | to build a binary tree of 100000 nodes requires one to generate 1.2 million “keys” in the process |
| 12:51 | danlentz | so you tell me if it is useful to do that fast. |
| 12:53 | danlentz | n log n i guess |
| 12:53 | danlentz | 2 million |
| 12:53 | danlentz | something like that |
| 12:55 | danlentz | i felt like the reason they arent used more broadly in clojure is just because they didn’t seem very easy or fast to generate correctly] |
| 12:56 | danlentz | but I think the use of UUID |
| 12:57 | danlentz | that made me interested in them in the first place was the way they are used to implement a distributed transaction system in he CL graph-object database system http://github.com/lisp/de.setf.resource |
| 12:58 | danlentz | Dr. Anderson writes some pretty amazing code. I spent about two years pouring over it…. :) |
| 12:59 | danlentz | also, their use in peer-to-peer networks, although I’m not sure generating ID |
| 13:00 | danlentz | quickly is a big concern in that case |
| 13:08 | michaelr` | how to write this: (.. (js/jQuery "body") (addClass "app")) so it survives advanced compilation? |
| 13:09 | michaelr` | Currently compiles to this: jQuery("body").zj("app") |
| 13:09 | nullptr | short answer is use https://github.com/ibdknox/jayq |
| 13:09 | nullptr | longer answer is to either call addClass by name or create an externs file |
| 13:10 | michaelr` | nullptr: i'm using jquery's externs file.. |
| 13:10 | michaelr` | it has this: jQuery.prototype.addClass = function(arg1) {}; |
| 13:12 | michaelr` | nullptr: what do you mean to call it by name? |
| 13:16 | danlentz | i invoke thee by name of house Lannister |
| 13:16 | nullptr | michaelr`: ((aget jQuery "addClass") ...) |
| 13:17 | nullptr | but if you have an externs file w/addClass that shouldn't be necessary, not sure what's happening there |
| 13:19 | michaelr` | nullptr: i'm using the externs file for 1.9.0 with version 1.9.1, could this somehow be the reason? |
| 13:21 | nullptr | michaelr`: i wouldn't think so |
| 13:24 | gfredericks | somehow clj-http 1.0.1 is putting test.check in my uberjar |
| 13:24 | michaelr` | nullptr: i'm using the externs file for 1.9.0 with version 1.9.1, |
| 13:24 | michaelr` | could this somehow be the reason? |
| 13:25 | gfredericks | well more precisely [com.cognitect/transit-clj "0.8.259"] is |
| 13:25 | nullptr | michaelr`: doubtful, typically the externs processing avoids renaming for anything named there -- it's not terribly "smart" |
| 13:26 | dnolen | michaelr`: only if addClass is missing, or the externs.js not actually getting included, I suspect the later |
| 13:26 | dnolen | michaelr`: the externs file needs to be on the classpath, random location will not work |
| 13:26 | dnolen | not even a regular file path |
| 13:26 | gfredericks | oh I see it's https://github.com/cognitect/transit-clj/commit/640c35166740642f5c197c78883784acb993d7a1 |
| 13:27 | michaelr` | dnolen: thanks. I have it here resources/public/vendor/js/jquery-1.9.0.ext.js - it's supposed to be on the classpath, no? |
| 13:27 | dakrone | gfredericks: transit-clj is an optional dep, you should be able to exclude it |
| 13:28 | dnolen | michaelr`: no idea, I don't know anything your project.clj nor what you specified for :externs since you haven't shown us |
| 13:28 | nullptr | michaelr`: how are you referencing it? |
| 13:29 | michaelr` | ok wait, I think I put my :externs in the wrong place ;) |
| 13:30 | gfredericks | dakrone: yeah, that's what I'll be doing; created an issue in the meantime |
| 13:30 | gfredericks | dakrone: spurious deps probably don't normally bother anybody much but when it's a test lib it can cause a lot of confusion |
| 13:30 | dakrone | yeah, makes sense |
| 13:31 | Guest39789 | trying to build a tree from maps like [{:id 1} {:id 2 :parent 1}]: https://gist.github.com/martinklepsch/4902c514c235dfa85f84 |
| 13:32 | Guest39789 | I have a basic solution but I'd like to see if it can be improved etc |
| 13:34 | jjttjj | anyone have any experience getting global hotkeys to work with clojure in windows? |
| 13:34 | jjttjj | like hit F10 to do something without the program in focus |
| 13:35 | Guest39789 | jjttjj: I'd research how you can achieve it with Java and then go from there |
| 13:47 | aaelony | ~mapply |
| 13:47 | clojurebot | You could (defn mapply [f & args] (apply f (apply concat (butlast args) (last args)))) |
| 13:47 | aaelony | is there a way to use mapply with juxt to pass named args ? |
| 13:48 | justin_smith | aaelony: what do you want the calling form to look like? |
| 13:49 | aaelony | justin_smith: I have a vector of maps with keys, keys that I have in another vector. I ultimately need to collect the values for each key into a vector. |
| 13:50 | aaelony | something like (map (juxt ks) coll) I guess |
| 13:51 | justin_smith | ,(map (apply juxt [:a :b :c]) [{:a 0 :b 1 :c 2} {:a 1 :c 3 :d 4}]) ; like this? |
| 13:51 | creese | Anyone know a good lib for Twilio? |
| 13:51 | clojurebot | ([0 1 2] [1 nil 3]) |
| 13:51 | aaelony | whereas (map (juxt :a :b :c) coll) works but I'd like ks to be [:a :b :c] |
| 13:51 | justin_smith | aaelony: yeah (apply juxt coll) |
| 13:51 | justin_smith | like I did above |
| 13:51 | aaelony | justin_smith: cool. let me try it out... |
| 13:52 | justin_smith | mapply is about apply with function that use [ & {:keys [a b c]}] |
| 13:53 | aaelony | I see. I'm playing around with gg4clj and taking records from a database where the result set is a vector of maps. I believe gg4clj needs {:key [vector of values] :key2 [vector ...] ...} |
| 13:54 | aaelony | but if I have a lot of fields, I only want a couple, hence juxt |
| 13:58 | justin_smith | aaelony: merge-with conj ... one moment I'll have an example |
| 13:58 | aaelony | yeah, I'm actually thinking about a bunch of other options. maybe even transducers... |
| 14:00 | justin_smith | ,(let [raw [{:a 0 :b 1} {:a 1 :c "OK"} {:b 2 :c "hello"}] base-keys (into #{} (mapcat keys raw))] (apply merge-with conj (zipmap base-keys (repeat [])) raw)) |
| 14:00 | clojurebot | {:c ["OK" "hello"], :b [1 2], :a [0 1]} |
| 14:00 | justin_smith | where likely "raw" would actually be your function input |
| 14:00 | aaelony | very cool |
| 14:01 | justin_smith | it even preserves order |
| 14:02 | aaelony | awesome stuff |
| 14:03 | justin_smith | I wonder if that (into #{} ...) needs to wrap the mapcat or not |
| 14:03 | justin_smith | well I know for a fact it doesn't need to, I just wonder if making a set before zipmapping is a net win or not |
| 14:06 | aaelony | thank you justin, still playing with it myself |
| 14:06 | aaelony | many thanks |
| 14:18 | justin_smith | aaelony: OK, both with and without jit turned on, the version without (into #{} ) wrapping the mapcat was faster |
| 14:18 | justin_smith | only a little, but hey, its simpler too |
| 14:34 | lasergoat | hi, i have a very strange AOT compilation issue i was hoping someone would help me with. Somehow, adding a dependency to storm-core causes my usage of clj-time.coerce to break |
| 14:34 | modulus | Hi. A few versions ago the use of the clojure repl, at least from lein, became problematic with a spanish keyboard layout. Does anyone know if any improvements are coming on this, and if so, when? |
| 14:34 | lasergoat | i have a minimal reproduction of the issue: https://github.com/icambron/storm-time |
| 14:34 | justin_smith | lasergoat: this rings a bell, something about storm-core having aot'd deps |
| 14:35 | lasergoat | justin_smith: i see |
| 14:35 | justin_smith | modulus: what OS do you use? |
| 14:35 | modulus | win8 |
| 14:36 | lasergoat | justin_smith: was there a workaround? (it is true that storm-core also depends on clj-time and thus I guess AOTs it into the jar) |
| 14:36 | justin_smith | OK. I would have suggested rlwrap otherwise (I assume it would be better localized than the java lib that lein uses with nrepl for input handling) |
| 14:36 | justin_smith | lasergoat: that's the part I don't know. maybe there is something about it on SO or the mailing list if nobody recalls here? |
| 14:37 | lasergoat | my brief search didn't find anything, but i can do some more digging |
| 14:37 | modulus | Probably what is most annoying is that it's a reversion. This used to work. Oh well. |
| 14:38 | justin_smith | modulus: one thing you can try is running a vanilla clojure repl - it will lack the nrepl features, but it may be more usable |
| 14:38 | justin_smith | modulus: java -cp (output of lein cp goes here) clojure.main |
| 14:38 | justin_smith | I don't know how to do stdout substitution in the windows shell, sorry |
| 14:38 | modulus | How would I do this? I guess I'm too used to lein to be aware how to run this by itself. |
| 14:39 | justin_smith | modulus: lein cp will output a classpath |
| 14:39 | modulus | ah i will try that |
| 14:39 | justin_smith | java -cp <that classpath> clojure.main |
| 14:39 | justin_smith | you may need quoting around the classpath part |
| 14:39 | modulus | yes, likely |
| 14:43 | modulus | hmm doesn't look like this will fit the command line length limit |
| 14:45 | lasergoat | what's the best way to search this channels logs? |
| 14:46 | lasergoat | since either my google-fu isn't good enough to find this issue or the previous discussion of it may have actually been here |
| 14:47 | godd2 | lasergoat have you tried googling "freenode log clojure" |
| 14:48 | lasergoat | ah, that pointed me in the right direction, thanks |
| 14:48 | lasergoat | site:http://www.raynes.me/logs/irc.freenode.net/clojure/ |
| 14:48 | lasergoat | was how i wanted to prefix my search |
| 14:52 | lasergoat | justin_smith: thanks for the help. That should get me started at least |
| 14:52 | aaelony | justin_smith: makes sense to remove without the into#{} , since there shouldn't be duped keys anyways. |
| 14:52 | justin_smith | oh, cool |
| 14:52 | aaelony | justin_smith: gosh my english is terrible |
| 15:17 | drbobbeaty | Has anyone used the :javac-options in Leiningen? I ask because I'm compiling a lot of Java code (SOAP) and it's barfing on OutOfMemory, but the -J-Xms32m or -Xms32m options are coming back as "illegal args" to javac. (running 1.7.0_71 on OS X, if that matters) |
| 15:24 | michaelr` | drbobbeaty: The compiler oom's? |
| 15:24 | drbobbeaty | Yup |
| 15:24 | michaelr` | because -Xmx I think is only for the jvm |
| 15:24 | drbobbeaty | And I'm a little afraid that Leiningen is placing the options to javac *after* the files, and in 1.7, I think that might be considered illegal. |
| 15:25 | justin_smith | drbobbeaty: maybe you need ^:replace - I know that is sometimes needed with :jvm-opts |
| 15:25 | drbobbeaty | Yeah, but putting the -J in from is supposed to pass it to the VM of the compiler. I have tested it independently, and the -J-Xms32m is the right argument to javac. |
| 15:25 | drbobbeaty | justin_smith: I'm not familiar with that metadata tag, can you possibly please elaborate? |
| 15:26 | justin_smith | :some-config ^:replace [opts...] |
| 15:26 | justin_smith | it tells lein to replace the defaults, instead of the default (merging in) |
| 15:27 | justin_smith | drbobbeaty: eg. this is needed if lein provides a default arg that contradicts the option you want (this comes up with hotspot options) |
| 15:27 | justin_smith | so in your case you could try :javac-options ^:replace [...] |
| 15:27 | drbobbeaty | justin_smith: I'll give it a go. Thanks. |
| 15:28 | drbobbeaty | justin_smith: Tried it... didn't work out. I'm going to see if I can get Leiningen to log what it's doing - I see the log messages in the code, I just want to see them output... more digging. |
| 15:29 | drbobbeaty | justin_smith: Thanks for the help, though |
| 15:29 | justin_smith | drbobbeaty: have you tried :eval-in pprint to get the effective project.clj? |
| 15:30 | drbobbeaty | justin_smith: No... I didn't know that trick, I'm just looking at my project.clj in the editor. |
| 15:37 | michaelr` | drbobbeaty: never met :eval-in but there is an easy to use plugin lein-pprint |
| 15:37 | ane | is it possible to do structural typing with defrecord and protocols? as in, is it possible to avoid specifying the protocols i am implementing? |
| 15:37 | drbobbeaty | michaelr`: Thanks, I'll try it. |
| 15:38 | lasergoat | ok, so more specifically the problem is that storm-core contains older versions of the dependency i'm trying to use and it's winning the war for the classpath. thus anything i'm using from clj-time that didn't exist in the prehistoric version causes a compiler error |
| 15:39 | bloawler | Hi! I'm trying to get the Leiningen repl working, I'm following a tutorial, and when I execute " (require '[clojure.zip :as zip]) " a FileNotFound exception is raised. Is there some specific setup needed to load these libraries into the lein repl? |
| 15:39 | lasergoat | in other words: https://issues.apache.org/jira/browse/STORM-169 |
| 15:39 | dan_b | lasergoat: have you tried something like |
| 15:39 | dan_b | [ring "1.3.2" :exclusions [org.clojure/java.classpath]] |
| 15:39 | dan_b | on yout project.clj |
| 15:40 | dan_b | obviously varying the package names to the ones you're having trouble with ;-0) |
| 15:40 | lasergoat | like trying to exclude clj-time from my storm dependency? i did try that, had no effect |
| 15:40 | justin_smith | dan_b: the issue is that storm compiles deps into itself |
| 15:40 | dan_b | dunno then, sorry |
| 15:41 | lasergoat | yeah, something about how it actually AOTs them -- lein doesn't seem to be able to override that? (it's becoming increasingly painful that i don't understand how this stuff works under the hood) |
| 15:45 | lasergoat | bloawler: that should work out of the box |
| 15:46 | justin_smith | bloawler: if (require '[clojure.zip :as zip]) doesn't work, the first thing I would check for is a typo |
| 15:46 | justin_smith | the second thing would be an insanely old clojure version I guess? |
| 15:46 | justin_smith | bloawler: what lein version are you using? |
| 15:54 | bloawler | justin_smith: 2.5.1, just upgraded through brew |
| 15:56 | gfredericks | is there a ring middleware for printing exceptions that prints the ex-data too? |
| 15:56 | bloawler | full exception: https://gist.github.com/anonymous/d3eee5c3c3d7e2e0ad00 |
| 15:56 | justin_smith | bloawler: like I said, typo |
| 15:56 | justin_smith | s/closure/clojure |
| 15:56 | bloawler | ahmigad |
| 15:56 | bloawler | i make this same spelling error in my google searches |
| 15:56 | bloawler | shoulda caught it |
| 15:57 | kungi | ikitommi_: Did you ever use compojure-api together with friend, and if ... can you give me some pointers on how to use it? |
| 15:57 | bloawler | thanks /embarrassed |
| 15:57 | justin_smith | it's a fair mistake for a newcomer, you were spelling the word correctly as far as the real world is concerned :) |
| 16:28 | gfredericks | hypirion: ping |
| 16:31 | hyPiRion | gfredericks: pong |
| 16:31 | gfredericks | hyPiRion: leiningen issue 1757 |
| 16:31 | gfredericks | would this cause `lein with-profile +foo uberjar` to be ineffective? |
| 16:31 | gfredericks | w.r.t. resource-paths in particular |
| 16:33 | hyPiRion | gfredericks: no, I think that should be fine |
| 16:34 | hyPiRion | I could imagine it being broken though, it has been painful in the past |
| 16:34 | ikitommi_ | kungi: for no good reason, have rolled own auth libs. Restructurings like :roles #{:admin} |
| 16:35 | gfredericks | hyPiRion: cool I'll dig deeper |
| 16:35 | gfredericks | hyPiRion: specifically I'm seeing the correct set of resource-paths if I `lein with-profile +foo pprint` yet still the file does not make it into the uberjar |
| 16:35 | gfredericks | going to make a user.clj and monkeypatch myself some logging or something |
| 16:36 | hyPiRion | gfredericks: Have you attached the ^:leaky metadata on foo? |
| 16:36 | hyPiRion | that was a breaking change that somehow got through |
| 16:36 | gfredericks | the what?? |
| 16:36 | lazybot | gfredericks: What are you, crazy? Of course not! |
| 16:37 | ikitommi_ | kungi: same for injecting components into routes via :components. These binding are mostly only few lines of code, but could add some common ones back to c-api. |
| 16:38 | hyPiRion | gfredericks: PR #1681 in lein |
| 16:38 | hyPiRion | https://github.com/technomancy/leiningen/pull/1681 |
| 16:38 | ikitommi_ | kungi: would love to see samples of friend or buddy integrated in. We could add those to examples. |
| 16:39 | gfredericks | hyPiRion: HUH. so ^:leaky is exactly what I want for this purpose and I shouldn't expect it to work without it? |
| 16:41 | hyPiRion | gfredericks: Yeah, but it's a breaking change 2.5.0 |
| 16:41 | hyPiRion | that landed in 2.5.0* |
| 16:43 | danlentz | justin_smith: and the others with whom I was discussing compile-time evaluation. I have been pointed to the (undocumented) #= reader macro which is equivalent to common lisp |
| 16:44 | danlentz | common-lisp #. which is what i wanted |
| 16:44 | gfredericks | hyPiRion: cool thanks! |
| 16:44 | hyPiRion | np |
| 16:44 | gfredericks | (inc hyPiRion) |
| 16:44 | lazybot | ⇒ 71 |
| 16:45 | justin_smith | danlentz: best known as a weird security issue ##(read-string "1 + 1 is ##(+ 1 1)") |
| 16:45 | lazybot | ⇒ 2 |
| 16:45 | justin_smith | err |
| 16:45 | justin_smith | &(read-string "1 + 1 is #=(+ 1 1)") |
| 16:45 | lazybot | ⇒ 1 |
| 16:46 | justin_smith | &(read-string "#=(+ 1 1)") |
| 16:46 | lazybot | java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false. |
| 16:46 | justin_smith | :P |
| 16:47 | gfredericks | hyPiRion: based on me just trying it I suspect #1718 (uberjar-name) is the same issue |
| 16:47 | gfredericks | should I comment and close it? |
| 16:48 | gfredericks | or is it a bug because :uberjar-name shouldn't require ^:leaky? |
| 16:49 | hyPiRion | I think it shouldn't require ^:leaky, but I'll have to look into the details again. There's a PR (#1849) for solving #1718 which I'll have a look at during the weekend |
| 16:49 | gfredericks | hyPiRion: okay cool, thanks again |
| 16:49 | hyPiRion | anytime |
| 17:02 | campeterson | Hey all, forgive me if this is is a weird question. I have a keyword :large? which correspond to a function name in the (ns image.core). I require image.core as image. I want to do this: (image/large? some_image) but I'm not sure how put the ns & function name together to evaluate it. |
| 17:03 | justin_smith | campeterson: why not just call image/large? |
| 17:04 | justin_smith | and where does this keyword come in again? |
| 17:05 | campeterson | justin_smith: I actually have a list of keywords which function names |
| 17:05 | campeterson | ‘(:large? :medium? :small?) |
| 17:06 | justin_smith | why do you need these keywords in a list? |
| 17:07 | campeterson | It’s how the data is stored. They are rules. |
| 17:07 | campeterson | My task is to check and make sure all the rules match (returning true or false) |
| 17:08 | campeterson | “Here are a list of functions. Let me know if they’re all true or not” |
| 17:08 | campeterson | It’s stored as data |
| 17:08 | campeterson | “Rules” |
| 17:08 | justin_smith | if that's what you want, then why are you using keywords instead of the functions themselves? |
| 17:09 | justin_smith | ,((every-pred [number? even? pos?]) 2) |
| 17:09 | clojurebot | true |
| 17:09 | justin_smith | if you just had a list of the functions, you could use every-pred |
| 17:10 | campeterson | good point |
| 17:10 | amalloy | justin_smith: ITYM ((every-pred number? even? pos?) 2), amusnigly |
| 17:10 | justin_smith | wait, oh that worked by accident |
| 17:10 | justin_smith | lol |
| 17:10 | justin_smith | (inc amalloy) |
| 17:10 | lazybot | ⇒ 239 |
| 17:11 | amalloy | your version happens to work because ([x y z] 2) returns z |
| 17:11 | justin_smith | right |
| 17:11 | justin_smith | campeterson: so it would be ##((apply every-pred [number? even? pos?]) 2) |
| 17:11 | lazybot | ⇒ true |
| 17:11 | justin_smith | using your list of functions of course |
| 17:12 | justin_smith | and yeah, you could write a function that takes a list of keywords and makes a list of functions from it, but if you can use functions, that's simpler |
| 17:12 | campeterson | What I’m doing (arguably very hacky) is akin to calling some_image.send(image/large?) |
| 17:13 | campeterson | the problem is I need to store the list of functions to call in the map |
| 17:13 | justin_smith | campeterson: if it has to be plain data and not functions, you can use symbols instead of keywords, then use resolve |
| 17:13 | justin_smith | but functions are simplest, if you can swing them |
| 17:14 | campeterson | The data is just json (written by a non-clojure system), so I’m afraid it has to be plain data |
| 17:14 | justin_smith | ,((apply every-pred (map resolve '[number? even? pos?])) 2) |
| 17:14 | clojurebot | true |
| 17:15 | justin_smith | or, since it is coming in as json, better to do explicit lookup to prevent a security hole |
| 17:15 | campeterson | sure |
| 17:15 | justin_smith | (get {:large? image/large ...} option) |
| 17:16 | justin_smith | or even (map {:large? image/larg ...} kw-options) |
| 17:16 | amalloy | (inc justin_smith) |
| 17:16 | lazybot | ⇒ 216 |
| 17:16 | campeterson | cool. Thanks for sticking through it. Kind of a weird issue |
| 17:51 | campeterson | justin_smith: thanks again. I got it. (though the code isn’t super pretty) ((ns-resolve (the-ns ‘image.core) (symbol (name :large?))) some-image) |
| 17:57 | justin_smith | campeterson: why use resolve at all instead of just using the functions in a lookup map? |
| 17:57 | justin_smith | you already know which functions will be valid, right? |
| 17:58 | justin_smith | campeterson: ##((apply every-pred (map {:even? even? :number? number? :pos? pos?} [:even? :number? :pos?])) 2) |
| 17:58 | lazybot | ⇒ true |
| 18:00 | justin_smith | campeterson: but of course in your case the hash map of keyword / function pairs would likely be a def, and the list of keywords to look up would be extracted from the json |
| 18:15 | kungi | ikitommi_: Ok I will try to generate a nice example. If I have some problems I will write to you tomorrow :-) |
| 18:21 | ikitommi_ | kungi: sounds great |
| 18:22 | nena30 | ola |
| 18:28 | arrdem | Is there an "aggressive" URL encoding tool? By default Java won't urlencode stuff like \. that's not really filesystem or URL safe. |
| 18:29 | amalloy | arrdem: uh, fairly sure java's url encoder correctly encodes urls |
| 18:30 | amalloy | if you want something that's "safe" in any arbitrary weird encoding context, you can base64 everything |
| 18:32 | kungi | ikitommi_: \o/ It works. Let's talk about the example tomorrow. |
| 18:32 | arrdem | amalloy: yeah that's the worst case approach for sure. |
| 18:33 | arrdem | eh forcibly encoding . as %2E is a superset of URL encoding and works for now. |
| 18:55 | hyPiRion | Has someone made a `with-out-str`, but for System/out? It seems pretty straightforward to implement, but I just want to know if there are any pitfalls I should attempt to avoid |
| 19:34 | aaelony | l |
| 19:34 | aaelony | sorry, wrong window. arrrrrrgh. |
| 20:03 | gfredericks | hyPiRion: well it'd be global is the big difference, right? |
| 20:03 | gfredericks | otherwise I don't know of any issues |
| 20:17 | gfredericks | any macro-lovers have thoughts about this? https://github.com/gfredericks/catch-data/pull/5 |
| 20:25 | om | gfredericks: wrapping the unquote seems a good idea to me... |
| 20:26 | gfredericks | om: oh, not about that part, I mean about my top level PR comments |
| 20:26 | om | but may be I missed the real point of your question |
| 20:26 | om | oh, sorry |
| 20:27 | om | (just that I did some wrapping of unquotings recently with the same concern as yours here) |
| 20:27 | gfredericks | yeah that's a totally normal macro thing |
| 20:31 | gfredericks | added another comment to it |
| 20:35 | verma | hey guys how do you like my sticker collage: http://udayv.com/mcti-clojure-workshop/stickers.html ? trying to get this up for a local workshop I am going to run this april, collecting stickers to give away from local and well-known clojure companies |
| 20:40 | ibash | verma: what is ithis? |
| 20:40 | verma | ibash: just a collection of stickers I'd be giving out to attendees at a clojure workshop I'd be running :) |
| 20:41 | verma | ibash: I am trying to get local companies and clojure companies to donate stickers :) |
| 20:41 | ibash | we have stickers |
| 20:41 | verma | SEND ME ZE STICKRZZ! |
| 20:41 | ibash | not a clojure company :( |
| 20:42 | verma | you're hanging out in #clojure, that's serious |
| 20:42 | verma | :) |
| 20:42 | ibash | I’m learning still |
| 20:42 | verma | ibash you can pm me your company name, email and I will send you a mail |
| 20:43 | ibash | .done |
| 22:44 | grantg | looking for the right way to remove from an atom containing a vector. i know for maps to (swap! the-atom dissoc key), but i cannot think of a nice way to do it with vectors by the value. |
| 22:45 | justin_smith | grantg: vectors don't support removal except of the last item |
| 22:46 | justin_smith | if you want to remove items in the middle, use a list / seq of some sort, and use the remove function |
| 22:47 | justin_smith | otherwise, the best bet with a vector is to use remove (which will give you a lazy seq back) and put the result into a vector |
| 22:48 | grantg | hmm... |
| 22:48 | justin_smith | or a set, those support removal by value |
| 22:48 | justin_smith | ,(disj #{:a :b :c :d :e} :b) |
| 22:48 | clojurebot | #{:e :c :d :a} |
| 22:48 | justin_smith | depends if you need something ordered or not I gues |
| 22:48 | justin_smith | s |
| 22:49 | grantg | the set may work. |
| 22:56 | TEttinger | grantg, also reset! if you don't mind changing the whole value |
| 22:56 | mfikes | Is there a cleaner way to map a list of fns across a sequence than this? (map #(%1 %2) [inc inc dec] [3 5 11]) |
| 22:56 | justin_smith | mfikes: juxt |
| 22:57 | Retsamtip | anyone know how to set session values in ring middleware? |
| 22:57 | justin_smith | ,(map (juxt inc inc dec) [3 5 11]) |
| 22:57 | grantg | justin_smith: the set works, thanks. |
| 22:57 | clojurebot | ([4 4 2] [6 6 4] [12 12 10]) |
| 22:57 | justin_smith | grantg: cool |
| 22:57 | grantg | TEttinger: didn't want to go to reset!, but thanks. :) |
| 22:58 | TEttinger | (inc juxt) |
| 22:58 | lazybot | ⇒ 20 |
| 22:58 | mfikes | ,(map #(%1 %2) [inc inc dec] [3 5 11]) |
| 22:58 | clojurebot | (4 6 10) |
| 22:58 | justin_smith | Retsamtip: (update-in my-response [:session :some-key] some-fn) or (assoc-in my-response [:session :some-key] value) |
| 22:58 | justin_smith | mfikes: oh, you don't want every function on every item, OK |
| 22:59 | Retsamtip | justin_smith: thanks, let me try that |
| 22:59 | justin_smith | Retsamtip: that's in order to generate the result of your handler of course, these are pure functions |
| 23:00 | Retsamtip | right, i guess that’s where i’m getting canfused |
| 23:00 | justin_smith | Retsamtip: so the update-in or assoc-in would wrap whatever you currently are returning |
| 23:00 | Retsamtip | to chain I have to return (handler request) |
| 23:00 | mfikes | justin_smith: Yeah. Honestly, I only ran into needing this once recently. It bothered me that I couldn't think of a clean solution, and thought I'd ask here. Maybe it doesn't occur frequently. |
| 23:01 | justin_smith | Retsamtip: right, so either you do the update inside handler, or you do (update-in (handler request) ...) |
| 23:01 | TEttinger | ((apply juxt [inc inc dec]) [3 5 11]) |
| 23:01 | TEttinger | ,((apply juxt [inc inc dec]) [3 5 11]) |
| 23:01 | clojurebot | #error{:cause "clojure.lang.PersistentVector cannot be cast to java.lang.Number", :via [{:type java.lang.ClassCastException, :message "clojure.lang.PersistentVector cannot be cast to java.lang.Number", :at [clojure.lang.Numbers inc "Numbers.java" 112]}], :trace [[clojure.lang.Numbers inc "Numbers.java" 112] [clojure.core$inc invoke "core.clj" 890] [clojure.core$juxt$fn__4463 invoke "core.clj" 2468... |
| 23:01 | TEttinger | agh |
| 23:02 | justin_smith | TEttinger: yeah, that juxt wants one arg |
| 23:02 | mfikes | justin_smith: TEttinger: Yeah. `juxt` feels like it must be part of the answer :) |
| 23:03 | justin_smith | it really only makes sense if all the functions are applied to an input |
| 23:03 | Retsamtip | justin_smith: does this look right, then? (update-in (handler req) [:session :some-key] "value") |
| 23:04 | justin_smith | ,(map apply [inc inc dec] (map list [3 5 11])) |
| 23:04 | clojurebot | (4 6 10) |
| 23:04 | justin_smith | Retsamtip: yes |
| 23:04 | justin_smith | the apply / list version is silly |
| 23:04 | mfikes | justin_smith: Wow. Cool. |
| 23:05 | justin_smith | mfikes: #(%1 %2) is better though |
| 23:05 | justin_smith | even if less aesthetically pleasing |
| 23:06 | mfikes | justin_smith: Yeah. I'm finding your other solution hard to tease apart. |
| 23:07 | TEttinger | it might make sense to (defn call [f & args] (apply f args)) |
| 23:07 | justin_smith | mfikes: apply takes any number of args, the first is called with the others as arguments, with the last ones all needing to be in a list |
| 23:07 | justin_smith | ,(apply + 1 [2]) |
| 23:07 | clojurebot | 3 |
| 23:07 | justin_smith | once you know that, my weird thing should make sense |
| 23:07 | justin_smith | though it's still silly |
| 23:07 | TEttinger | ,(defn call [f & args] (apply f args)) |
| 23:07 | clojurebot | #'sandbox/call |
| 23:08 | TEttinger | ,(map call [inc inc dec] [3 5 11]) |
| 23:08 | clojurebot | (4 6 10) |
| 23:08 | Retsamtip | justin_smith: thanks, not working for me. here’s the middleware http://pastebin.com/Vnsgmrba |
| 23:08 | TEttinger | ,(map call [+ - *] [3 5 11] [10 20 30]) |
| 23:08 | clojurebot | (13 -15 330) |
| 23:08 | Retsamtip | that last assoc-in does not seem to update the session |
| 23:09 | mfikes | TEttinger: Hmm. `call` seems useful :) |
| 23:09 | justin_smith | Retsamtip: why is (handler req) on line 17? |
| 23:09 | Retsamtip | thought that’s what i need to return to chain |
| 23:09 | justin_smith | no |
| 23:10 | TEttinger | mfikes, if it comes up more than once it might be handy to define it |
| 23:10 | justin_smith | Retsamtip: remember I said, you need to wrap (handler req) with the session update |
| 23:10 | TEttinger | otherwise, #(%1 %2) should suffice |
| 23:10 | justin_smith | Retsamtip: because assoc-in is a pure function, if you don't return it, it may as well not be there - you create the session and throw it away |
| 23:11 | TEttinger | it's equivalent to #(apply %1 %&) anyway |
| 23:11 | TEttinger | (my call) |
| 23:11 | mfikes | TEttinger: right |
| 23:11 | Retsamtip | justin_smith: got it. so removing that return value should work. let me try it |
| 23:12 | justin_smith | Retsamtip: what you have there should work if you take out (handler req) on line 17 |
| 23:12 | justin_smith | Retsamtip: also, either take (handler req) out of your let block, or change the assoc in to (assoc-in response ...) |
| 23:12 | justin_smith | because there's no need to do the handler twice |
| 23:12 | Retsamtip | yes, works! thank you very much, now I understand my n00b mistake |
| 23:13 | justin_smith | Retsamtip: also, your code will be much easier to understand if you don't put multiple let bindings on one line |
| 23:13 | justin_smith | Retsamtip: best is one value / binding on each line of the binding vector |
| 23:13 | Retsamtip | good call, i’ll do that |