2015-10-04
| 00:19 | python476 | turns out after 1 hour, java throws a ThreadDeath exception. |
| 04:04 | roelof | Hello, I have to put a initial value here (reduce (fn [counter] (inc counter)) [1,2,3]) but where do I put it ? |
| 04:10 | expez | roelof: this is a good site to help answer such questions: https://clojuredocs.org/search?q=reduce |
| 04:11 | expez | not only do you get the docstring, but quite a few examples answering common questions as well as common gotchas |
| 04:12 | roelof | expez: thanks, I have read them and as far as I understand it , it must be this : (reduce (fn [counter] (inc counter)) 0 [1,2,3]) |
| 04:13 | roelof | but then I see this error message : clojure.lang.ArityException: Wrong number of args (2) passed to: core/eval6230/fn--6231 |
| 04:13 | expez | roelof: you are right, that's the right place ot put the seed value, but that's not related to the error you're getting |
| 04:13 | expez | roelof: the function passed to reduced must take two arguments, yours only takes one |
| 04:14 | expez | ,(reduce (fn [counter _] (inc counter)) 0 [1,2,3]) |
| 04:14 | roelof | thanks I will hit the book why counter needs two arguments instead of 1 |
| 04:14 | clojurebot | 3 |
| 04:15 | expez | roelof: reduce reduces multiple values two a single value |
| 04:16 | expez | roelof: to do that the reducing argument considers two things: the accumulated value so far, and the value of the next element in the input sequence |
| 04:16 | expez | the reducing function* |
| 04:17 | expez | ,(reduce (fn [accumulator n] (+ accumulator n)) [1 2 3 4]) |
| 04:17 | clojurebot | 10 |
| 04:17 | expez | the final value is the value in the accumulator |
| 04:17 | expez | once all inputs have been consumed |
| 04:18 | roelof | thanks for the explanation |
| 04:19 | roelof | finnaly that challenge on 4clojure solved. Can this solution be improved : (fn [list] (reduce (fn [counter _] (inc counter)) 0 list)) |
| 04:20 | expez | I take it the exercise is to re-implement count? |
| 04:20 | roelof | expez: yes, I try to solve that exercise |
| 04:22 | expez | I think using reduce is a fine choice |
| 04:23 | roelof | expez: so the solution cannot be shorter ? |
| 04:24 | expez | ,(reduce #(+ %1 %2) (range 10)) |
| 04:25 | clojurebot | 45 |
| 04:26 | expez | I thought this might work: (reduce #(inc %1) 0 (range 10)) but it doesn't :p |
| 04:27 | expez | so no, I don't think you can make it much shorter |
| 04:30 | roelof | expez: thanks, now the next challenge, make Fibonacci Sequence. so again a nice one to think how to solve this. First thought something like map |
| 04:31 | luma | i guess you could (reduce + (map (constantly 1) list)) |
| 04:34 | expez | (while true (future 1)) is fine, right? I'm not leaking any resources? |
| 04:40 | amalloy | if you don't mind forkbombing yourself |
| 04:40 | amalloy | this spins up threads as fast as your OS is capable of |
| 04:41 | expez | amalloy: obv that doesn't happen in practice, I tested this to find out if I leaked memory when I didn't use future-cancel or ever retrieve the value of the un-interesting futures. |
| 04:42 | expez | running the code above at the repl seems to only produce a cpu load, not a memory load |
| 04:43 | amalloy | you don't leak anything permanent, but whether your thread demand outpaces supply is a matter of luck and/or system power |
| 04:44 | expez | great, thanks |
| 06:05 | visof | hi guys |
| 06:06 | visof | how can i convert this haskell (fmap (fmap f) z) to clojure? (fmap #(fmap f %) z) ? |
| 06:08 | expez | ,(map (partial map inc) [[1 2] [3 4]]) |
| 06:08 | clojurebot | ((2 3) (4 5)) |
| 06:08 | expez | visof: ^ |
| 06:09 | expez | Is there a general version of subvec which works seqs? |
| 06:12 | djcoin | visof: in which order are your argument? |
| 09:04 | ob-sed | hey this gu in ##hardware is complaining clojure uses up too much ram |
| 09:13 | ob-sed | i told him to shut his mouth the hell up |
| 09:13 | ob-sed | his name is crocket |
| 09:15 | oddcully | ><((((*> |
| 09:19 | taylanub | ob-sed: that doesn't sound like a very friendly thing to do |
| 09:19 | ob-sed | taylanub: yeah but he's been saying the same thing for an hour, like a broken record, how: |
| 09:19 | ob-sed | "<crocket> I just wanted to say that "RAM is cheap" is not an excuse for thinking that it's ok to consume 160MB for a daemon whose only task is to send an HTTP request regularly." |
| 09:21 | oddcully | and then you /ignore:d it, right? |
| 09:25 | crocket | RAM is not so cheap. |
| 09:25 | taylanub | do we have a !mods command? shall I invoke it? |
| 09:26 | crocket | If RAM was cheap, it should be ok for every small linux daemon or every kernel driver to consume 160-250MB. |
| 09:26 | crocket | Then, linux won't fit in 16GB RAM. |
| 09:26 | taylanub | ob-sed: crocket: get a room and leave the channel alone |
| 09:27 | taylanub | (I'm new here but I assume this is common sense.) |
| 09:27 | crocket | taylanub, you from ##hardware? |
| 09:30 | crocket | I came here to say it because some people in this channel said as if every program could afford to consume hundreds of MB. This is physically impossible. |
| 09:40 | Bronsa | ob-sed: clojure doesn't fit all usecases, I wouldn't use it in memory-constrained embedded devices. |
| 09:40 | Bronsa | also please don't bring issues from other channels here |
| 09:40 | wasamasa | some people are having a hard time just accepting that java was made for running a single application on a server |
| 09:44 | wasamasa | ob-sed: generally, the channel to take such things to is #freenode |
| 11:17 | gfredericks | okay I might make a library that's a stupid datastore where it just appends edn events to a file and keeps a reduction of all the events in memory |
| 11:17 | gfredericks | unless somebody tells me it already exists |
| 11:27 | gfredericks | I think I should probably name it "webscale" |
| 11:32 | sakalli | join #commonlisp |
| 11:32 | sakalli | sry ;) |
| 12:12 | xtreak | Hi, what is the difference between require and :require. require needs the vector to be quoted and :require doesn't need it. Saw them used interchangeably. Any difference? |
| 12:37 | luxbock | xtreak: require is the function that loads a namespace from the classpath, and because the namespace hasn't been loaded up yet you need to quote its argument as the symbols it uses haven't been defined yet |
| 12:39 | xtreak | Thanks. Why do some tutorials use :require keyword for loading libraries. Any difference or is it a matter of preference? |
| 12:40 | luxbock | xtreak: so the `ns` that's used in the ns-declaration of a file is a macro, and it uses kind of a mini-DSL to create and reference other namespaces, and :require is part of that mini-DSL |
| 12:40 | luxbock | it gets translated to calling `require` in the end |
| 12:41 | luxbock | I don't know why it uses :require instead of just the symbol, probably because then it it would be even more confusing why one needs the quote and the other doesn't |
| 12:42 | luxbock | the reason you don't need to use quote with :require is because it's a macro so the symbols inside don't get evaluated |
| 12:43 | luxbock | https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L5529 |
| 12:43 | luxbock | this is what `ns` does for you :) |
| 12:43 | xtreak | Yes. Its been confusing. I thought that :require is used to access the parts like a hashmap. But that doesn't make sense as its followed by a vector. Thanks for clearing that its a macro. |
| 12:45 | xtreak | I read up source for require as it does some apply operation along with filtering the keywords used in vector. Thanks for the reference :) |
| 12:46 | xtreak | Also a question about the error messages in clojure really scare me away as I am a newbie. Is there a way to make runtime checks and throw some exceptions? Any project under development on that? |
| 12:48 | luxbock | xtreak: do you know about the pre and post -conditions you can add to functions? |
| 12:48 | luxbock | http://blog.fogus.me/2009/12/21/clojures-pre-and-post/ |
| 12:48 | xtreak | Like take the second argument of map to see if its a function with (type f) and then throw up an error if not. |
| 12:48 | luxbock | then there's Prismatic's Schema which is should fit into what you were asking quite well: https://github.com/Prismatic/schema |
| 12:49 | xtreak | Ofcourse keywords can be used in maps too just wondering if its possible.. |
| 12:49 | luxbock | if you use Emacs/CIDER, it sanitizes the stacktraces quite nicely |
| 12:50 | luxbock | other editors might do the same but I haven't used them |
| 12:50 | xtreak | Pre and post? I came across constraint programming in D lang . not sure if its the correct term. It has precondition and post condition blocks. Is it similar? |
| 12:51 | luxbock | xtreak: check out the blog post I linked |
| 12:52 | justin_smith | gfredericks: that stream of events in a file thing? if you are allowed to format the edn via transit, it's called kafka, and I've found it pretty awesome |
| 12:52 | justin_smith | gfredericks: side effects of that stream of events in a file, is it works as a logged communication channel |
| 12:52 | xtreak | I use emacs too ;) I will try out cider. I mostly use lein repl . sure will give it a try. Will check out the blog post. Thanks a lot :) |
| 12:54 | luxbock | cider has this nice popup that pretty prints and allows you to filter the stacktraces which I find really helpful |
| 12:54 | luxbock | sometimes you want more and sometimes less details |
| 12:55 | gfredericks | justin_smith: the use case is super casual though, where you don't want to run a separate process and you want to store the data in git |
| 12:55 | xtreak | Read the post. Quite similar to D lang. Cool to learn that :) |
| 13:00 | xtreak | Does clojure lazy sequences create intermediate collections. The reason to create transducers where Rich Hickey says in strongloop video IIRC that they avoid intermediate collections. So when I say (map inc (filter odd? (range 10))). Does 1 from range collection pass through filter and to map in same call or filter creates an intermediate collection and feeds to map? If so how is filter lazy? |
| 13:01 | justin_smith | xtreak: yes, that map / filter / range creates three lazy seqs, and you use one of them |
| 13:02 | justin_smith | it's lazy because it creates its own collection, which doesn't need to realize as many inputs as its source does |
| 13:03 | justin_smith | errr s/inputs/elements on the end there |
| 13:04 | xtreak | Sorry. I couldn't fully grok that. |
| 13:04 | justin_smith | filter walks along the collection that range created, making its own collection |
| 13:05 | justin_smith | it will create results only if its own collection is consumed |
| 13:06 | xtreak | When I say (range 10) it returns me a promise like thing to generate it when needed. Filter walks through but doesn't generate until consumed? Little confusing that it walks over the range collection but doesn't generate. |
| 13:09 | justin_smith | xtreak: it doesn't walk through the range until it needs to produce results |
| 13:09 | justin_smith | but it might walk multiple elements of the range to produce one output |
| 13:10 | justin_smith | it's a promise like thing, just like range is |
| 13:10 | xtreak | So transducers remove the intermediate collection by filter and make it as a single pipeline of different operations than making intermediate collections for each map/filter. Am i correct? |
| 13:10 | justin_smith | right, it composes operations without creating new collections in between |
| 13:11 | justin_smith | also this means you can transduce on channels too (which are not even collections) |
| 13:11 | justin_smith | and one could define ways to transduce on other non-collection sources of input as well |
| 13:11 | roelof | why do I see this error message : Mismatched argument count to recur, expected: 1 args, got: 2 on this code : http://lpaste.net/142293 |
| 13:12 | xtreak | Is the multiple elements mean 32 elements at a time? Sorry to be confusing. Read somewhere that clojure does that. |
| 13:12 | justin_smith | roelof: you start the loop with one value, and then try to recur with two |
| 13:13 | justin_smith | roelof: maybe you meant (loop [counter 2 n n] ...) |
| 13:13 | justin_smith | and you can ditch the let |
| 13:14 | justin_smith | roelof: loop is like let, where you declare a binding symbol, and an initial value, so you need two elements in the vector for each binding |
| 13:15 | xtreak | justin_smith any place to study more about clojure lazy sequnces? |
| 13:17 | xtreak | They look interesting. Am on sicp now.. Will be interesting to compare clojure implementation, streams in sicp and lazy sequences implementation in other languages. |
| 13:17 | justin_smith | xtreak: have you looked at the sequence docs on clojure.org? http://clojure.org/sequences |
| 13:21 | roelof | justin_smith: thanks, now trying to find out why I see a null pointer exception here : http://lpaste.net/142297 |
| 13:21 | xtreak | They look a little hazy to me. From wat i understand they are an interface that are implemented by different data structures. Whats an ISeq? |
| 13:21 | justin_smith | ISeq is the interface |
| 13:22 | xtreak | Maybe am trying to grasp too much being a clojure beginner still ;) |
| 13:22 | justin_smith | one implementation of ISeq is lazy-seq, if you use that function, the seq you are creating is lazy |
| 13:23 | xtreak | Is sequence a data structure or an implementation of ISeq interface. Sry little confused. |
| 13:24 | justin_smith | roelof: after the first recur, answer is not a thing you can use get to look something up in, it will be nil, because you are calling (assoc number number) |
| 13:24 | xtreak | Its a logical list says the link |
| 13:25 | justin_smith | xtreak: a sequence is some data that implements the ISeq interface |
| 13:25 | justin_smith | and the interface ensures that any implementation of ISeq can be used as if it were a linked list (regardless of implementation) |
| 13:25 | roelof | pff, what I try to do is summing the right numbers ( n -1) + ( n - 2) and adding it up to answer which will [ 0 1] |
| 13:25 | roelof | so again back to the manual |
| 13:26 | justin_smith | roelof: right, but in assoc, you only provide two args, and both are numbers |
| 13:26 | roelof | justin_smith: oke, so I forget to mention answer :( |
| 13:26 | justin_smith | roelof: wait, no, do you even provide a second arg to assoc? don't you just want conj? |
| 13:27 | justin_smith | roelof: if what you want is to add to the vector, you don't want to use assoc there, you want to use conj |
| 13:27 | justin_smith | and you need to provide answer as the first arg to conj |
| 13:27 | roelof | oke, then im confusing those two |
| 13:27 | justin_smith | roelof: after the first recur, should answer be [0 1 1] or should it be [1 1] ? |
| 13:28 | roelof | justin_smith: it schould be [ 0 1 1 ] |
| 13:28 | roelof | and after that [ 0 1 1 2] |
| 13:29 | justin_smith | OK, so your last arg to recur should be (conj answer (+ (get answer (- counter 2)) (get answer (- counter 1)))) |
| 13:29 | justin_smith | you also had the args to get backward |
| 13:29 | justin_smith | ,(get 1 [0 1]) |
| 13:29 | clojurebot | nil |
| 13:29 | justin_smith | which causes nil |
| 13:29 | justin_smith | ,(get [0 1] 1) |
| 13:29 | clojurebot | 1 |
| 13:30 | justin_smith | that's the version you want |
| 13:30 | xtreak | So all data structures that implement ISeq allow themselves to be accessible like a linked list? When I say (seq x) it returns a sequence a linked list representation of the given structure to be precise. |
| 13:31 | xtreak | ,(seq (into [] (range 10))) |
| 13:31 | clojurebot | (0 1 2 3 4 ...) |
| 13:31 | justin_smith | roelof: your code will be much easier if the (recur) were refactored to be a let block like (if (= counter n) answer (let [counter (inc counter) n n a (get answer (- counter 2)) ...] (recur ...))) |
| 13:31 | xtreak | ,(seq (into {} (range 10))) |
| 13:31 | clojurebot | #error {\n :cause "Don't know how to create ISeq from: java.lang.Long"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: java.lang.Long"\n :at [clojure.lang.RT seqFrom "RT.java" 535]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 535]\n [clojure.lang.RT seq "RT.java" 516]\n [clojure.lang.ATransientMap conj "ATransientMap.java" 42]\n [cloju... |
| 13:32 | roelof | justin_smith: thanks, my first try to make fib numbers works :) |
| 13:32 | justin_smith | xtreak: yes |
| 13:32 | xtreak | :):) |
| 13:32 | justin_smith | xtreak: the into {} fails because {} expects each element to be a two element vector |
| 13:32 | justin_smith | ,(seq [1 2 3]) |
| 13:33 | clojurebot | (1 2 3) |
| 13:33 | roelof | justin_smith: oke, so the calculation in the let block and the recur only with the variables you mean |
| 13:33 | justin_smith | ,(type (seq [1 2 3])) |
| 13:33 | clojurebot | clojure.lang.PersistentVector$ChunkedSeq |
| 13:33 | justin_smith | roelof: right, instead of having so much logic on one line |
| 13:33 | justin_smith | xtreak: if you are ready for more complex details, there's the fact that vectors create a chunked seq |
| 13:34 | xtreak | Things make much better sense now. What will be the structure of a lazy sequence? |
| 13:34 | justin_smith | xtreak: the only thing that makes lazy sequences, is the function lazy-seq |
| 13:34 | justin_smith | check out the doc and examples for that function |
| 13:34 | roelof | can I then do more then 1 thing after the false, Or schould I make it works with both in a ( ) ? |
| 13:34 | justin_smith | roelof: that's what the let does |
| 13:34 | roelof | oke, learned another thing :) |
| 13:35 | xtreak | ,(type (seq #{1 2 3})) |
| 13:35 | clojurebot | clojure.lang.APersistentMap$KeySeq |
| 13:35 | justin_smith | ,(if false :ORLY (let [a 0 b 1] (+ a b)) ; roelof |
| 13:35 | clojurebot | #<RuntimeException java.lang.RuntimeException: EOF while reading> |
| 13:35 | justin_smith | err |
| 13:35 | justin_smith | ,(if false :ORLY (let [a 0 b 1] (+ a b))) ; roelof |
| 13:35 | clojurebot | 1 |
| 13:36 | justin_smith | xtreak: also I hope you found this link on the sequence page http://clojure.org/lazy |
| 13:36 | xtreak | Is it really a linked list? sets return a different name :( |
| 13:36 | justin_smith | xtreak: it can act like a linked list |
| 13:36 | justin_smith | the point is that vectors and sets and etc. each return a totally different type, adapted to their source data |
| 13:37 | justin_smith | but they all use the same interface, the interface our sequence functions all use, so you can ignore the concrete type most of the time |
| 13:37 | justin_smith | because it's a sequence, and that's all that matters usually |
| 13:39 | xtreak | So it doesn't matter to the consumer of the sequence too as they only traverse and perform the actions returning a sequence. Right? |
| 13:39 | justin_smith | right |
| 13:39 | justin_smith | they are effectively using a linked list - even though none of these are a canonical linked-list type |
| 13:40 | roelof | justin_smith: it this what you mean ; http://lpaste.net/142298 . It gives a error message on let but it produces the right output |
| 13:41 | justin_smith | roelof: the recur should be outside the binding vector |
| 13:42 | roelof | I saw it later, Did change that |
| 13:42 | justin_smith | also, I think you want a + there, I was thinking you would do more like (let [counter (inc counter) n n a (get answer (- counter 2)) b (get answer (- counter 1))] (recur counter n (+ a b))) |
| 13:43 | justin_smith | roelof: also, notice that we can now tell n never changes, so it doesn't need to be a loop arg, and you could take it out of both loop and recur |
| 13:43 | xtreak | I looked into the lazy sequence link. Its a little heavy for me. I will go chunk by chunk. Please add other links too that will help me when I get stuck. Thanks a lot for your walkthrough bearing the newbie. Learnt a lot of things justin_smith . Is there any log of clojure channel available ? For my reference. |
| 13:44 | justin_smith | oh yeah, lazybot makes one when it is around, as does clojurebot - one moment |
| 13:44 | justin_smith | xtreak: http://clojure-log.n01se.net/ |
| 13:45 | Draco_ | I have a hashmap such as {"x" {"user" "stuff"} "user" "z" "y" [{"user" "K"} {"abc" "def"}]}, how do I extract all values of "user" to get a vector such as ["stuff", "z", "K"] ? I've looked at tree-seq, postwalk, but am really stuck. |
| 13:46 | xtreak | Sweet :) accidentally closed my irc client and lost all the msgs. Thanks a lot :) |
| 13:47 | roelof | justin_smith: when I do this : http://lpaste.net/142299 I see the null exception error again |
| 13:49 | justin_smith | ,(keep #(get % "user") (tree-seq coll? seq {"x" {"user" "stuff"} "user" "z" "y" [{"user" "K"} {"abc" "def"}]})); Draco_ |
| 13:49 | clojurebot | ("z" "stuff" "K") |
| 13:49 | luxbock | roelof: you're trying to use `get` on a number, i.e. the sum of a and b |
| 13:50 | roelof | luxbock: so I have to change the arguments |
| 13:50 | justin_smith | roelof: yeah, remember it can't just be (+ a b) it has to be (conj answer (+ a b)) - that was my error |
| 13:50 | Draco_ | sweet justin_smith! That really works. I can see how keep is useful in there. |
| 13:50 | luxbock | roelof: also binding something to itself like you do with `n` in the let doesn't really serve any purpose |
| 13:50 | justin_smith | luxbock: yeah, I mentioned that n wasn't really needed as a loop arg either |
| 13:53 | roelof | oke, changed the code to this : http://lpaste.net/142300 but still the same error, I could be easier if I could see what the values of a b and answer were |
| 13:57 | luxbock | roelof: it would help if you also showed how you are calling the function as it's impossible for us to know what `answer` is here |
| 13:57 | justin_smith | luxbock: it's [0 1] |
| 13:57 | oddcully | you could print them? wrap your block in a do, println first and keep the old code last in the do |
| 13:57 | oddcully | or use a debugger |
| 13:58 | roelof | luxbock: I call it this way (fib2 [0 1] 5) |
| 13:58 | roelof | oddcully: does Lighttable has a debugger then ? |
| 13:59 | justin_smith | roelof: it's an off by one because you need to inc counter after calculating a and b |
| 14:00 | justin_smith | roelof: https://www.refheap.com/110257 |
| 14:01 | roelof | justin_smith: that was it. it's not working fine with this code : http://lpaste.net/142301 |
| 14:02 | justin_smith | not working fine? |
| 14:03 | roelof | its working fine. One thing I have to change I think and that is making it work only with n. |
| 14:03 | justin_smith | roelof: oh, you can do that with multiple arities |
| 14:03 | justin_smith | which is a cool feature, see if you can figure it out |
| 14:04 | roelof | I did it this way : (loop [counter 2 n n answer [0 1]] |
| 14:04 | justin_smith | oh that's legit too |
| 14:04 | roelof | and change fib2 to this (defn fib2 [n] |
| 14:05 | justin_smith | also you can take n out of the loop bindings (as it doesn't change) |
| 14:05 | roelof | next task. Look if I can make it work with map . I think its better then loop recur |
| 14:05 | bendavisnc | can anyone tell me how to disable auto indent in intellij with clojure? |
| 14:05 | bendavisnc | maybe i'm being dumb but i can't find it any where and it's driving me bananas |
| 14:06 | justin_smith | roelof: map would only make sense if you were mapping over some collection though... I don't think that makes sense here |
| 14:06 | justin_smith | roelof: but you could totally do it with iterate / drop-while |
| 14:07 | roelof | oke, in programming clojure is stated you almost never need loop reccur , Most things can be done with just the core things |
| 14:07 | xtreak | Fib code with iterate is very elegant |
| 14:08 | oddcully | bendavisnc: ctlr-alt-a, enter indent and hope for the best? |
| 14:08 | oddcully | roelof: dunno about lighttable. i don't use it |
| 14:09 | xtreak | https://en.m.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci |
| 14:10 | bendavisnc | oddcully, ugh my alt is tied to my desktop, ubuntu, and still, that's no solution |
| 14:11 | oddcully | mine too, but i swapped it with super_l to i still have the old alt |
| 14:11 | rhg135 | roelof: usually reduce can replace loop |
| 14:12 | justin_smith | rhg135: not for a generative thing like fib though |
| 14:12 | rhg135 | Usually :-P |
| 14:14 | roelof | oke, thanks, a lot of things to try tomorrow |
| 14:23 | luxbock | ,(reduce #(conj % (apply + (subvec % (- (count %) 2) (count %)))) [1 1] (range 10)) |
| 14:23 | clojurebot | #error {\n :cause "Wrong number of args (2) passed to: sandbox/eval26/fn--27"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (2) passed to: sandbox/eval26/fn--27"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 36]\n [clojure.lang.LongRange reduce "LongRange.java... |
| 14:24 | luxbock | ,(reduce (fn [x _] (conj x (apply + (subvec % (- (count x) 2) (count x)))) [1 1] (range 10))) |
| 14:24 | clojurebot | #error {\n :cause "Unable to resolve symbol: % in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: % in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: % in this context"\n ... |
| 14:24 | luxbock | bleh |
| 14:24 | luxbock | wouldn't that count as using reduce to replace loop? |
| 14:29 | devangshah | can i destructure as well as pass exact params (i.e. without destructuring) to the functions? |
| 14:30 | roelof | justin_smith: I like the iterate solution here : https://en.m.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci, Tommorow I want to look if I can make it work with a end argument instead of the whole map |
| 14:46 | zimablue | what's the recommended way to sandbox code? like allow a user to create a function with specified inputs and outputs and no side effects? I've seen clojail but it looks out of development, it basically gives you a whitelist capability? |
| 14:47 | gfredericks | devangshah: I'm not sure what your question means, you might try giving an example |
| 14:48 | justin_smith | devangshah: maybe two arities, one that provides every input as a separate arg, called by another arity that destructures a single input? |
| 15:05 | triss | so how would one find out what platform they're running on in Clojure? |
| 15:05 | triss | i.e. OS X/Windows/Linux |
| 15:07 | justin_smith | triss: (System/getProperty "os.name") |
| 15:07 | justin_smith | ,(System/getProperty "os.name") |
| 15:07 | triss | thanks justin_smith |
| 15:07 | clojurebot | #error {\n :cause "denied"\n :via\n [{:type java.lang.SecurityException\n :message "denied"\n :at [clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69]}]\n :trace\n [[clojurebot.sandbox$enable_security_manager$fn__835 invoke "sandbox.clj" 69]\n [clojurebot.sandbox.proxy$java.lang.SecurityManager$Door$f500ea40 checkPropertyAccess nil -1]\n [java.lang.System getProperty ... |
| 15:07 | justin_smith | :P |
| 15:33 | rhg135 | what is the algorithmic complexity of clojure.core/sort ? |
| 15:34 | rhg135 | O(n)? |
| 15:35 | justin_smith | rhg135: it uses java.util.Arrays/sort |
| 15:35 | justin_smith | rhg135: nlog(n) http://www.programcreek.com/2013/11/arrays-sort-comparator/ |
| 15:37 | justin_smith | Arrays/sort is quicksort for primitives, mergesort for Object |
| 15:39 | rhg135 | I'm dealing with objects |
| 15:40 | rhg135 | Is it okay to use a vector then sort it? |
| 15:41 | rhg135 | I want a structure similar to a sorted set but with duplicates and I don't require lookup |
| 15:43 | justin_smith | you could just conj then sort for each addition, that's fast for merge-sort |
| 15:44 | rhg135 | I didn't know if it'd perform well. Thanks |
| 15:52 | rhg135 | unfortunately, sort returns a seq |
| 15:52 | rhg135 | not a vector |
| 15:53 | rhg135 | I can deal with this I think, but it is an issue |
| 16:00 | skeuomorf | Is there a builtin function to test if something is an atom or not? |
| 16:00 | skeuomorf | or will I have to use `instance?`? |
| 16:02 | justin_smith | skeuomorf: I think instance? would be the thing, unless you'd prefer to test if it is a thing you can deref, or swap!, which would use satisfies? |
| 16:03 | skeuomorf | justin_smith: I see |
| 16:15 | arrdem | ping |
| 16:21 | gfredericks | justin_smith: crap I think I made webscale https://github.com/gfredericks/webscale |
| 16:23 | arrdem | gfredericks: it's been done before https://github.com/clojure-grimoire/simpledb |
| 16:24 | gfredericks | arrdem: where were you three hours ago when I was asking about this |
| 16:24 | arrdem | gfredericks: afk same as I've been for about two months now |
| 16:24 | arrdem | ish |
| 16:24 | gfredericks | arrdem: wait this isn't persistent? |
| 16:24 | arrdem | what isn't persistent |
| 16:24 | gfredericks | simpledb |
| 16:25 | gfredericks | to disk |
| 16:25 | gfredericks | I mean |
| 16:25 | arrdem | it does persist... at a 2 minute clock tick |
| 16:25 | gfredericks | oh okay good I'm still original |
| 16:26 | arrdem | so simpledb uses one file for the whole damn thing... |
| 16:26 | arrdem | what's yours do? |
| 16:26 | arrdem | note that simpledb is circa 2011 from ibdknox |
| 16:26 | arrdem | I just cleaned it up a bit |
| 16:26 | gfredericks | arrdem: webscale is about storing events on disk, not the current state |
| 16:26 | gfredericks | so it just appends events as they happen |
| 16:27 | gfredericks | and the in-memory state is based on a reduce function over the events |
| 16:27 | arrdem | gfredericks: that's kinda nice |
| 16:27 | gfredericks | arrdem: I've got like three different uses for it and was tired of implementing it over and over |
| 16:28 | arrdem | gfredericks: gotcha nice |
| 16:28 | arrdem | I may have to play with that later |
| 16:29 | arrdem | fake partial datomic implementation number.... |
| 16:29 | gfredericks | :) |
| 16:29 | gfredericks | the use case is basically whenever you say "I want my data to be human-readable and probably stored in a git repo" |
| 16:30 | gfredericks | the first serious thing I'm going to do with it is to try to replace 4clojure's mongo usage |
| 16:31 | arrdem | hum.... |
| 16:31 | arrdem | I don't think this'd be a net memory savings or I'd try to apply it to Grimoire as well |
| 16:31 | arrdem | I'm using simpledb right now to implement some server side analytics |
| 16:31 | gfredericks | do you spit the whole state to a new file every 2 min? |
| 16:32 | arrdem | same file but yeah |
| 16:32 | arrdem | what are append only logs |
| 16:32 | arrdem | why do I need those |
| 16:32 | gfredericks | is that a question? |
| 16:32 | arrdem | I'm being silly |
| 16:32 | gfredericks | I suspected |
| 17:31 | lxsameer | hey folks, I have a websocket server using Immutant, I want to put it under a heavy load and benchmark it, what solution do you suggest ? |
| 17:31 | arrdem | ab for the win |
| 17:32 | arrdem | unless you have a number of URLs you want to test in which case you need something else |
| 17:34 | sameerynho | arrdem: i don't have any url |
| 17:35 | sameerynho | arrdem: and does ab supports websocket load ? |
| 17:44 | monsta | Excuseme, when I see a funtion that finish with a asterisk what is the meaning? (example: dosomething*) |
| 17:44 | arrdem | monsta: the -* convention is for helper functions or implemenetations which the author didn't have a better name for. |
| 17:45 | monsta | Is there any online guide to this nameing convention that I can't refer too? |
| 17:46 | arrdem | not really. |
| 17:46 | arrdem | gfredericks: is there one I don't know of? |
| 17:47 | gfredericks | oh actually |
| 17:48 | monsta | Thanks you |
| 17:48 | arrdem | I know that the earmuffs convention is mentioned on clojure.org |
| 17:49 | gfredericks | this might https://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 17:49 | arrdem | nah only mentions _ and earmuffs |
| 17:50 | arrdem | and -? |
| 17:52 | arrdem | $seen yogthos |
| 17:52 | arrdem | lazybot wya |
| 17:53 | rhg135 | he's on an indefinate vacation |
| 17:54 | arrdem | lame |
| 17:54 | arrdem | clearly I need to start running an instance in addition to Grim... |
| 17:54 | rhg135 | indeed |
| 17:55 | arrdem | well that's one way to get the $grim plugin justin_smith helped me build merged after a year of waiting :P |
| 17:57 | kap | hello, new to Clojure, how would I go about working with binary numbers? Do I need to convert them first? 0b1 throws an "Invalid number format" error, but hexes like 0xA works |
| 17:58 | arrdem | yeah so 0b1 doesn't wor, but 2r010 will be 2 |
| 17:58 | kap | oh, 'r' for arbitrary radix? |
| 17:58 | gfredericks | ,24r24 ;; e.g. |
| 17:58 | clojurebot | 52 |
| 17:58 | arrdem | I think it only goes up to 36r.... |
| 17:58 | gfredericks | ,36r1 |
| 17:58 | clojurebot | 1 |
| 17:59 | gfredericks | ,37r1 |
| 17:59 | clojurebot | #<NumberFormatException java.lang.NumberFormatException: Radix out of range> |
| 17:59 | kap | excellent, thanks :) |
| 17:59 | gfredericks | ,(Long/parseLong "101010" 2) |
| 17:59 | clojurebot | 42 |
| 17:59 | gfredericks | ,(.toString 42 2) |
| 17:59 | clojurebot | #error {\n :cause "No matching method found: toString for class java.lang.Long"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "No matching method found: toString for class java.lang.Long"\n :at [clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 53]}]\n :trace\n [[clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 53]\n [clojure.lang.Reflector invokeInstan... |
| 17:59 | gfredericks | ,(Long/toString 42 2) |
| 17:59 | clojurebot | "101010" |
| 18:00 | kap | is the recommended form to use 'r' for portability across clojures? |
| 18:00 | gfredericks | rather than what? |
| 18:01 | kap | parsing with java |
| 18:02 | gfredericks | oh well the use cases are different |
| 18:02 | gfredericks | I guess you could use read-string to do runtime stuff more portably |
| 18:14 | qmm | what's the reasoning in avoiding static types? |
| 23:12 | cfleming | ,(into {} (partition 2 1 [["(" ")"] ["{" "}"] ["[" "]"] ["#{" "}"] ["(" ")"]])) |
| 23:12 | clojurebot | {"(" ")", "{" "}", "[" "]", "#{" "}"} |
| 23:13 | cfleming | Say whut |
| 23:13 | cfleming | Here (Clojure 1.7.0) I get "ClassCastException clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry" |
| 23:14 | justin_smith | cfleming: there's an error message bug |
| 23:14 | justin_smith | cfleming: it will complain about the first thing in the collection, instead of the type of the collection itself |
| 23:15 | cfleming | Ok, now I'm confused, actually |
| 23:15 | justin_smith | cfleming: one moment, I will find the case that causes the error message bug |
| 23:16 | cfleming | My first example should not work, because sure enough partition returns a seq of seqs, not vectors |
| 23:16 | cfleming | But I have no idea what clojurebot is on about there, how did it get that map from that input? |
| 23:16 | justin_smith | ,(into {} '(([a b] c))) ; the error message bug |
| 23:16 | clojurebot | #error {\n :cause "clojure.lang.Symbol cannot be cast to java.util.Map$Entry"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.Symbol cannot be cast to java.util.Map$Entry"\n :at [clojure.lang.ATransientMap conj "ATransientMap.java" 44]}]\n :trace\n [[clojure.lang.ATransientMap conj "ATransientMap.java" 44]\n [clojure.lang.ATransientMap conj "ATransientMap.java" 17]\n [... |
| 23:16 | justin_smith | oh it's fixed! |
| 23:17 | justin_smith | (locally it complains about persistentvector) |
| 23:17 | justin_smith | ,*clojure-version* |
| 23:17 | clojurebot | {:major 1, :minor 8, :incremental 0, :qualifier "alpha3"} |
| 23:17 | justin_smith | COOL |
| 23:17 | justin_smith | ,(into {} '((a b) (c d))) |
| 23:17 | clojurebot | #error {\n :cause "clojure.lang.Symbol cannot be cast to java.util.Map$Entry"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.Symbol cannot be cast to java.util.Map$Entry"\n :at [clojure.lang.ATransientMap conj "ATransientMap.java" 44]}]\n :trace\n [[clojure.lang.ATransientMap conj "ATransientMap.java" 44]\n [clojure.lang.ATransientMap conj "ATransientMap.java" 17]\n [... |
| 23:17 | justin_smith | OK still not quite right |
| 23:18 | cfleming | Ok, so this is actually what I want: |
| 23:18 | cfleming | ,(into {} (map vec (partition 2 1 [["(" ")"] ["{" "}"] ["[" "]"] ["#{" "}"] ["(" ")"]]))) |
| 23:18 | clojurebot | {["(" ")"] ["{" "}"], ["{" "}"] ["[" "]"], ["[" "]"] ["#{" "}"], ["#{" "}"] ["(" ")"]} |
| 23:18 | Ilie | Hello, I've developed a simple file named functions.clj that I'm trying to import in riemann.config.clj and I keep getting #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: get-owner-email in this context, compiling: |
| 23:18 | cfleming | No idea how clojurebot got the result above. |
| 23:18 | Ilie | I'm trying to use get-owner-email in riemann.config.clj (the file resides in functions.clj), I've tried to add it using (include "functions'clj") and (load-file "functions.clj") but I still have the same issue, can you please advise? |
| 23:19 | justin_smith | Ilie: why not require by the full namespace? |
| 23:19 | justin_smith | if your PWD is in the same dir, it would be (load-file "functions"), but it's better to use require |
| 23:20 | Ilie | I've created the files using leingen, the files are at the same level, I tried (require 'seiso') but it still doesn't work |
| 23:20 | justin_smith | Ilie: that's not how clojure single quotes work |
| 23:20 | Ilie | #<CompilerException java.io.FileNotFoundException: functions (No such file or directory) |
| 23:20 | justin_smith | if the full ns name was (ns seiso ...), it would be (require 'seiso) |
| 23:21 | justin_smith | but if the ns has a compound name, you need to provide the rest of the name, regardless of your working directory |
| 23:23 | Ilie | http://pastebin.com/1aaG0F86 |
| 23:23 | Ilie | I don't have a ns in riemann.config.clj |
| 23:25 | Ilie | I've tried now with (require 'seiso) but I get the same error |
| 23:27 | justin_smith | Ilie: so why do you have this clj file at the top level of your project, outside the src/ tree? |
| 23:27 | namra | Ilie: and the function.clj resides in the same directory as riemann.conf.clj? |
| 23:28 | Ilie | I'm just starting out with clojure, adding it to src/ will allow me to use (require 'seiso) ? |
| 23:28 | Ilie | What I want is to separate the functionality and to use functions in my riemann config |
| 23:29 | justin_smith | Ilie: then why not make a clojure project, and require riemann as a library, rather than adding files to random places in riemann? |
| 23:29 | namra | Ilie: how do you executed riemann, because by it'll look for the files within the same directory as riemann.config |
| 23:29 | Ilie | len run -- riemann.config.clj |
| 23:29 | Ilie | lein* |
| 23:30 | justin_smith | Ilie: and putting it inside src is more likely to work - source files are looked up on the classpath, and src/ will be on the classpath by default |
| 23:31 | Ilie | Thank you for the suggestions guys, really helpful, I'll try that now |
| 23:31 | Ilie | I copied the file to src/seiso.clj and I'm using (require 'seiso) but I get the same error |
| 23:32 | namra | more likely src/riemann/seiso.clj |
| 23:33 | Ilie | Same thing, I guess I'll just have to inline everything in riemann.config.clj |
| 23:33 | justin_smith | namra: that would only work if the ns was riemann.seso |
| 23:34 | justin_smith | *reimann.seiso |
| 23:34 | namra | justin_smith: oh thanks |
| 23:34 | justin_smith | namra: the namespace is just a single element top level ns (which is discouraged, but newbies gonna newb) |
| 23:35 | namra | but i think he might not need to put it into src, because all extra configuration for riemann is read at runtime (startup) |
| 23:36 | namra | thus when doing lein run on passes it the config option and provides the main configuration file. riemann than looks in the same directory as the main config for includes that are specified within it. |
| 23:37 | justin_smith | namra: oh, I had no idea |
| 23:37 | namra | anything else would mean baking it right into riemann itself |
| 23:37 | namra | cause i use it myself, but never from master. only prebuild uberjars |
| 23:43 | Ilie | I copied the file in src/riemann and src/ and restarted riemann but I get the same error, not sure what to try next |
| 23:54 | Ilie | I moved my folder to src/riemann/<my_folder> and it works now, thank you guys for the help |
| 23:54 | justin_smith | glad you sorted it out... |
| 23:56 | namra | Ilie: and in the riemann.config.clj there's only an (include "functions.clj")? |
| 23:56 | namra | or do you use a proper namespace as justin_smith mentioned previously? |
| 23:57 | Ilie | namra, I don't have a namespace in riemann.config.clj (there is no namespace by default) |
| 23:57 | Ilie | I tested again but I can't use the function I wrote so I'm just going to inline everything |
| 23:58 | namra | i mean in your functions.clj within src/riemann/<my_folder> |