2014-07-20
| 01:04 | wenshan | Hi all, I'm new to Clojure. Wondering if I can do something equivalent to generator.next (generator is implemented using lazy-seq) in Clojure. |
| 01:05 | TEttinger | wenshan, is generator.next a python thing? |
| 01:06 | TEttinger | oh I see your question |
| 01:06 | TEttinger | I think yes, let me check |
| 01:06 | wenshan | yes |
| 01:07 | TEttinger | lazyseqs work with nth , for one thing |
| 01:07 | wenshan | I'd like to do (while (< curr 1000) (progn ...)) |
| 01:07 | TEttinger | ,(nth (repeat 10) 99) |
| 01:07 | clojurebot | 10 |
| 01:08 | TEttinger | oh that might be easier with take |
| 01:08 | TEttinger | do you have any code now? |
| 01:08 | TEttinger | there's also of course loop/recur with an iterator |
| 01:08 | wenshan | yes, I have a prime number generator |
| 01:09 | wenshan | trying to get the largest palindrome prime number under 1000 |
| 01:09 | TEttinger | palindrome being in base 10? |
| 01:09 | TEttinger | like 11 |
| 01:09 | wenshan | yes |
| 01:10 | wenshan | convert the base 10 integer to string, than check whether it's a palindrome |
| 01:10 | TEttinger | so your generator returns an infinite lazy seq? |
| 01:10 | TEttinger | (doc take-while) |
| 01:10 | clojurebot | "([pred coll]); Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects." |
| 01:10 | wenshan | I think so, I copied it from http://stackoverflow.com/questions/960980/fast-prime-number-generation-in-clojure |
| 01:11 | wenshan | It has an equivalent python version, which returns a generator (infinite) |
| 01:11 | TEttinger | ,(defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) 5)) |
| 01:11 | clojurebot | #'sandbox/prime? |
| 01:12 | TEttinger | ,(take-while #(< % 1000) (filter prime? (range))) |
| 01:12 | clojurebot | (2 3 5 7 11 ...) |
| 01:12 | TEttinger | ,(count (take-while #(< % 1000) (filter prime? (range)))) |
| 01:12 | clojurebot | 168 |
| 01:13 | TEttinger | so there are 168 probably primes under 1000, sound right? |
| 01:13 | TEttinger | *probable primes |
| 01:15 | TEttinger | ,(last (filter #(.equals (str %) (apply str (rseq (str %)))) (take-while #(< % 1000) (filter prime? (range))))) |
| 01:15 | clojurebot | #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Reversible> |
| 01:15 | TEttinger | ,(last (filter #(.equals (str %) (apply str (reverse (str %)))) (take-while #(< % 1000) (filter prime? (range))))) |
| 01:15 | clojurebot | 929 |
| 01:15 | TEttinger | there you go |
| 01:15 | TEttinger | clojure has to be the best language I know for this kind of development |
| 01:16 | TEttinger | (I don't even have a REPL open, and I can still solve the problem -- thanks clojurebot!) |
| 01:17 | TEttinger | ,(take-while #(and (> 928 %) (< % 1000)) (filter prime? (range))) |
| 01:18 | clojurebot | #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: prime? in this context, compiling:(NO_SOURCE_PATH:0:0)> |
| 01:18 | TEttinger | haha it unloaded it |
| 01:18 | TEttinger | ,(defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) 5)) |
| 01:18 | clojurebot | #'sandbox/prime? |
| 01:18 | TEttinger | ,(take-while #(and (> 928 %) (< % 1000)) (filter prime? (range))) |
| 01:18 | clojurebot | (2 3 5 7 11 ...) |
| 01:18 | TEttinger | ,(take-while #(and (> % 928) (< % 1000)) (filter prime? (range))) |
| 01:18 | clojurebot | () |
| 01:19 | TEttinger | ,(take-while #(and (> % 900) (< % 1000)) (filter prime? (range))) |
| 01:19 | clojurebot | () |
| 01:19 | TEttinger | hm |
| 01:22 | TEttinger | and to verify, |
| 01:22 | TEttinger | ,(clojure.string/join " " (second (split-with #(< % 920) (take-while #(< % 1000) (filter prime? (range)))))) |
| 01:22 | clojurebot | "929 937 941 947 953 967 971 977 983 991 997" |
| 01:23 | TEttinger | wenshan, do you have the gist of it now? |
| 01:31 | Aaln | (println "hello everyone") |
| 01:31 | TEttinger | ,(Integer/toString (last (filter #(.equals (Integer/toString % 36) (apply str (reverse (Integer/toString % 36)))) (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range))))) 36) |
| 01:31 | clojurebot | "11" |
| 01:31 | TEttinger | the last base 36 palindrome prime |
| 01:31 | TEttinger | under 1000 |
| 01:32 | TEttinger | ,(Integer/toString (last (filter #(.equals (Integer/toString % 30) (apply str (reverse (Integer/toString % 30)))) (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range))))) 30) |
| 01:32 | clojurebot | "131" |
| 01:32 | TEttinger | neat |
| 01:32 | Aaln | ,(Integer/toString (last (filter #(.equals (Integer/toString % 30) (apply str (reverse (Integer/toString % 30)))) (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range))))) 30) |
| 01:32 | clojurebot | "131" |
| 01:32 | TEttinger | hey Aaln |
| 01:32 | Aaln | .(println "hello world") |
| 01:32 | Aaln | ,(println "hello world") |
| 01:32 | clojurebot | hello world\n |
| 01:32 | Aaln | hey @Tettinger |
| 01:32 | TEttinger | how goes? |
| 01:33 | Aaln | Pretty good, working on a clojure app atm |
| 01:33 | Aaln | What's going on with you? |
| 01:34 | TEttinger | just fiddling with clojure while I wait for mono to compile |
| 01:34 | Aaln | What is 'mono'? |
| 01:34 | TEttinger | it's an implementation of MS .NET libs (and stuff like C#) for other platforms than windows |
| 01:35 | TEttinger | ClojureCLR can run on it, not just C# by a long shot. I'm trying to get my C# code that uses a Java lib to work on linux |
| 01:35 | Aaln | So .net can compile to *** language? |
| 01:36 | TEttinger | no, .NET is just the platform (VM) |
| 01:36 | TEttinger | .NET is actually microsoft's one for windows |
| 01:36 | TEttinger | mono doesn't do everything .NET does, but it runs almost everywhere |
| 01:37 | TEttinger | java and clojure have an edge though because they are easier to get working on android, I would say |
| 01:37 | Aaln | Not understanding... Does mono allow you to use .NET on other platforms asides from windows? |
| 01:37 | TEttinger | yes |
| 01:37 | TEttinger | and .NET is what C# runs on |
| 01:37 | Aaln | Awesome |
| 01:38 | TEttinger | it would be if it worked! |
| 01:38 | Aaln | lol |
| 01:38 | Aaln | Have you used to clojure for android? |
| 01:59 | wenshan | TEttinger:Thanks a lot, the isProbablePrime thing looks elegant here. Why did you choose 5 as certainty? |
| 02:00 | TEttinger | that's what it had in the stack overflow answer, tbh |
| 02:00 | TEttinger | you can probably go lower for under 1000 numbers |
| 02:01 | wenshan | I see |
| 02:01 | wenshan | this is really great |
| 02:01 | TEttinger | actually let's check now! |
| 02:02 | TEttinger | ,(count (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range)))) |
| 02:02 | clojurebot | 168 |
| 02:02 | TEttinger | ,(count (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 2) (range)))) |
| 02:02 | clojurebot | 169 |
| 02:02 | TEttinger | ah! |
| 02:03 | TEttinger | lower certainties may result in false positives, but 2 is really low |
| 02:03 | TEttinger | ,(count (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 9) (range)))) |
| 02:03 | clojurebot | 168 |
| 02:03 | TEttinger | so we can be fairly sure there are 168 primes under 1000 |
| 02:03 | wenshan | makes sense |
| 02:05 | TEttinger | ,(clojure.set/difference (set (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 2) (range)))) (set (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range))))) |
| 02:05 | clojurebot | #<ClassNotFoundException java.lang.ClassNotFoundException: clojure.set> |
| 02:06 | TEttinger | ,(require clojure.set) |
| 02:06 | clojurebot | #<CompilerException java.lang.ClassNotFoundException: clojure.set, compiling:(NO_SOURCE_PATH:0:0)> |
| 02:06 | TEttinger | ,(require 'clojure.set) |
| 02:06 | clojurebot | #<SecurityException java.lang.SecurityException: denied> |
| 02:31 | wenshan | TEttinger: I can understand the logic (have some emacs-lisp background), but the hash symbols used in #(.equals ...) and (take-while #(< % 1000) ...) are something new. What I found on stackoverflow says it's a reader macro that expands to (var foo). Am I reading the correct thread? |
| 02:32 | TEttinger | no, not quite. # is a special part of a reader macro that is used for a lot of purposes |
| 02:32 | TEttinger | here, it's lambdas |
| 02:32 | TEttinger | ,(map inc [1 2 3]) |
| 02:32 | clojurebot | (2 3 4) |
| 02:32 | TEttinger | ,(map #(+ % 1) [1 2 3]) |
| 02:32 | clojurebot | (2 3 4) |
| 02:33 | TEttinger | so #() is a lambda that takes args by number, like %1, %2, %3, and % (with no number)is an alias for %1 |
| 02:33 | TEttinger | ,(map (fn [n] (+ n 1)) [1 2 3]) equivalent to this |
| 02:34 | clojurebot | (2 3 4) |
| 02:34 | wenshan | I'm trying to understand it in elisp, I guess it's equivalent to (mapcar (lambda (x) (+ x 1)) '(1 2 3)) |
| 02:34 | TEttinger | but if you see # elsewhere it depends on what's after it. |
| 02:35 | TEttinger | ,(map inc #{1 2 3}) |
| 02:35 | clojurebot | (2 4 3) |
| 02:35 | TEttinger | #{} is a set |
| 02:35 | TEttinger | unsorted, but checks for uniqueness |
| 02:35 | wenshan | hmm, I see |
| 02:35 | TEttinger | and yes, i think you're right about the elisp |
| 02:36 | TEttinger | #' is what you mentioned about vars |
| 02:36 | TEttinger | ,#'inc |
| 02:36 | clojurebot | #'clojure.core/inc |
| 02:36 | wenshan | #() is really handy, I like it |
| 02:36 | luxbock | http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 02:36 | TEttinger | it's great for one-liners, it's why clojure is one of the best lisps for short programs |
| 02:36 | luxbock | this is a good resource |
| 02:37 | wenshan | thanks :D |
| 02:39 | TEttinger | wow, that's really handy luxbock |
| 02:39 | TEttinger | I forgot about the #"" regexps, though I use them plenty |
| 02:54 | TEttinger | (inc luxbock) |
| 02:54 | lazybot | ⇒ 1 |
| 02:54 | luxbock | yay |
| 02:55 | luxbock | internet points |
| 02:55 | TEttinger | clojurebot: symbols |are| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 02:55 | clojurebot | Roger. |
| 02:56 | TEttinger | symbols? |
| 02:56 | clojurebot | symbols are http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 02:56 | TEttinger | hm, symbols are also a type |
| 02:56 | TEttinger | clojurebot: unlearn symbols |are| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 02:56 | clojurebot | In Ordnung |
| 02:56 | TEttinger | symbols? |
| 02:56 | clojurebot | http://clojure.org/data_structures#toc10 |
| 02:57 | TEttinger | clojurebot: punctuation |means| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 02:57 | clojurebot | 'Sea, mhuise. |
| 02:57 | TEttinger | punctuation? |
| 02:57 | clojurebot | punctuation means kind of fun |
| 02:57 | TEttinger | punctuation? |
| 02:57 | clojurebot | punctuation is preferred to a torrent of newlines |
| 02:57 | TEttinger | punctuation? |
| 02:57 | clojurebot | punctuation means unlearn symbols |
| 02:57 | TEttinger | gah |
| 02:58 | TEttinger | clojurebot: punctuation |is| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 02:58 | TEttinger | punctuation? |
| 02:59 | TEttinger | clojurebot: forget symbols are http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/ |
| 06:35 | rurumate | in storm-starter I've managed to start an nrepl connection on 4005 using 'mvn clojure:nrepl'. Now in emacs / cider I can connect to repl, and reload the word_count namespace, but jump-to-definition M-. doesn't work. Emacs says "unknown resource path". Any ideas? |
| 08:35 | at21 | Hi guys. How to install clojure libraries from clojars (for example https://clojars.org/ring) ? |
| 08:35 | at21 | I have leiningen installed successfully |
| 08:37 | at21 | Hi guys. How to install clojure libraries from clojars (for example https://clojars.org/ring) ? I have leiningen installed successfully |
| 08:38 | boxed | at21: in project.clj under :dependencies put [thelib “version”] and then run lein |
| 08:38 | boxed | if you can’t get it to work, put the project.clj on a pastebin and put in the link here |
| 08:40 | at21 | M-m, thank you. I'll try it |
| 08:48 | at21 | boxed: Now what? I've just put the library I want into project.clj in .lein/ directory |
| 08:49 | jkj | at21: profiles.clj ? |
| 08:49 | at21 | oh, yeap |
| 08:49 | at21 | profiles... |
| 08:50 | boxed | nono, the project.clj file in your own project |
| 08:53 | at21 | ok, If I put it in my project file what about other projects? |
| 08:53 | at21 | and what if I want to use it in REPL? |
| 08:53 | boxed | you should add dependencies for a project in that project… |
| 08:54 | boxed | if you do “lein repl” in the same folder as a project.clj you’ll get the dependencies |
| 08:54 | at21 | Isn't there anything like in python where you just install some package via PIP and you can use it anywhere by importing it? |
| 08:55 | boxed | you probably can.. but that is one of the worst things about python so why would you want to? :P |
| 08:55 | at21 | )) |
| 08:55 | at21 | why is that? |
| 08:55 | boxed | I say this as a full time python code :P |
| 08:55 | at21 | because it doesn't isolate things? |
| 08:55 | boxed | because then you move some code to another machine and it explodes |
| 08:55 | boxed | yea exactly |
| 08:56 | at21 | """if you do “lein repl” in the same folder as a project.clj you’ll get the dependencies""" Okay, how am I gonna get them? They will be downloaded right? |
| 08:58 | boxed | yea |
| 08:58 | boxed | and it checks that they’re signed properly etc |
| 08:59 | at21 | Okay, say there are downloaded. What if I want to use them in other project, but I don't have the internet connection. Wouldn't that be a problem? I mean I don't often have an internet |
| 08:59 | Glenjamin | dependencies are cached locally |
| 09:00 | Glenjamin | just not in a place they can be depended on implicitly :) |
| 09:00 | boxed | to be more precise: they are downloaded to a central place on your computer if they aren’t already in that central place |
| 09:02 | at21 | don't get it). So I can't store them to further use? |
| 09:03 | Glenjamin | they get downloaded to ~/.m2 |
| 09:03 | at21 | great |
| 09:03 | at21 | that's what i've been asking |
| 09:04 | at21 | so that means I can use them whenever I want without the internet (if they are downloaded already) by just pointing it in :dependencies? |
| 09:05 | Glenjamin | yes |
| 09:05 | at21 | Oh, great. Big thanks to <boxed> and <Glendjamin> |
| 09:06 | boxed | np |
| 09:19 | daGrevis | hi! i know there's lein repl. is there anything more advanced with syntax highlight and auto-complete? |
| 09:24 | justin_smith | daGrevis: cider for emacs and fireplace for vim aim at that, light table has its own editor integrated version of things, as does cursive (an intellij idea plugin) |
| 09:25 | daGrevis | justin_smith, but is there anything that's editor agnostic? |
| 09:28 | daGrevis | and another question if I may. i have a data-structure and i want to get a random element from it do something with it and return it from my function. how do i do that? |
| 09:29 | daGrevis | i mean exactly... i can't create a temporary variable and store things i will return later |
| 09:29 | daGrevis | i can't find anything like yield in python too so that's out |
| 09:30 | nathan7 | daGrevis: .WHAT DO YOU MEAN? |
| 09:30 | nathan7 | err |
| 09:30 | nathan7 | sorry for caps |
| 09:30 | nathan7 | daGrevis: (let [x (inc y)] ...) |
| 09:31 | nathan7 | daGrevis: tahdah, temp variable |
| 09:31 | daGrevis | hmm how could i explain it better without you doing in my place :D |
| 09:31 | nathan7 | daGrevis: `let` creates local variables |
| 09:31 | daGrevis | nathan7, right, but i can't change it no? |
| 09:31 | nathan7 | Correct, but you can make new things based on it |
| 09:31 | nathan7 | (let [x (inc x)] …) |
| 09:31 | nathan7 | that's basically x += 1 |
| 09:32 | daGrevis | https://gist.github.com/e17730a0d1c4bee11718 |
| 09:33 | nathan7 | Try `for` instead of dotimes |
| 09:33 | nathan7 | and no need to turn chain into a seq beforehand, by the way |
| 09:33 | daGrevis | right list comp! |
| 09:34 | daGrevis | nathan7, chain's a map |
| 09:34 | nathan7 | daGrevis: rand-nth should turn it into a seq by itself I think? |
| 09:34 | daGrevis | rand-nth won't work on map, only seq |
| 09:34 | Glenjamin | $source rand-nth |
| 09:34 | lazybot | rand-nth is http://is.gd/HVnhk6 |
| 09:34 | nathan7 | ,(rand-nth {:a :b}) |
| 09:34 | clojurebot | #<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap> |
| 09:34 | nathan7 | :( |
| 09:34 | daGrevis | told ya :) |
| 09:34 | nathan7 | silly |
| 09:34 | Glenjamin | it does this: (nth coll (rand-int (count coll)))) |
| 09:34 | nathan7 | yeah |
| 09:35 | Glenjamin | which makes a whole bunch of assumptions |
| 09:35 | nathan7 | mhm |
| 09:35 | nathan7 | yay dynamic typing |
| 09:35 | daGrevis | :) |
| 09:39 | daGrevis | i'm not sure for will be the best solution there |
| 09:40 | daGrevis | basically i have markov chain in format of {:word [:following :words] :word2 [...]} |
| 09:40 | daGrevis | and i want to choose key, then choose value of that key and repeat it 2 to 5 times |
| 09:42 | Glenjamin | something like (mapcat #(random-sample (val %)) (random-sample words)) |
| 09:42 | daGrevis | i'll just try recur it |
| 10:16 | daGrevis | i wrote what i wanted |
| 10:16 | daGrevis | it is so ugly :) |
| 10:26 | justin_smith | daGrevis: you may be able to express that in terms of iterate |
| 10:27 | daGrevis | justin_smith, https://gist.github.com/595f08e9b6612d1b5405 |
| 10:27 | daGrevis | i expressed it already |
| 10:27 | daGrevis | it's just fugly for now |
| 10:27 | justin_smith | and, regarding editor agnostic, no, I don't know of any tool that adds highlighting and completion to the repl that is not part of some editor |
| 10:28 | daGrevis | too bad. i didn't fell in love with vim-fireplace( |
| 10:29 | justin_smith | daGrevis: I mean you can simplify that loop you have to be in terms of iterate |
| 10:29 | justin_smith | because it is an iterate shaped problem |
| 10:30 | daGrevis | i will look into it, but i don't see how it's possible by simply iterating through map |
| 10:30 | justin_smith | ,(take 5 (iterate #(conj % (rand-int 10)) [])) |
| 10:30 | clojurebot | ([] [0] [0 3] [0 3 0] [0 3 0 1]) |
| 10:30 | justin_smith | that is not what iterate is |
| 10:30 | justin_smith | it doesn't "iterate through" anything |
| 10:30 | justin_smith | it repeatedly takes some action to build a result |
| 10:31 | justin_smith | also, depending on the length of the sequence you are building, pop will be much faster than last |
| 10:32 | daGrevis | ok i will look into iterate. sorry about not knowing what iterate is -- i'm new to this :) |
| 10:32 | justin_smith | and though (seq chain) is not redundant, (seq next-words) is |
| 10:33 | daGrevis | right, thanks |
| 10:33 | justin_smith | no need to apologize for not knowing, though assuming you know despite someone more experienced suggests it could be useful is likely to lead to wasting your own time :) |
| 10:34 | daGrevis | right. ok let me try with iterate |
| 10:36 | boxed | deGrevis: how does the input look? |
| 10:36 | daGrevis | iterate is something like generator |
| 10:36 | daGrevis | if i understand correctly |
| 10:37 | daGrevis | boxed, https://gist.github.com/41dbe86764e19228bc32 |
| 10:37 | justin_smith | daGrevis: my version, untested because I don't have the chain map |
| 10:37 | justin_smith | https://www.refheap.com/88388 |
| 10:37 | boxed | that’s a bit too vague for me to say anything :P |
| 10:38 | justin_smith | boxed: he has mentioned this before, it is a simplistic markov chain representation, keys are preceding words, vals are a seq of following words |
| 10:38 | boxed | daGrevis: I used a lot of core.match for making sense of not-super-nice datastructures, have you looked at that? |
| 10:39 | boxed | ah |
| 10:40 | daGrevis | here's better data set https://gist.github.com/94ec78b417a40c567d05 |
| 10:41 | daGrevis | not much better thought :) |
| 10:42 | daGrevis | justin_smith, it throws exception about not being able to pop empty vector |
| 10:43 | justin_smith | yeah |
| 10:43 | justin_smith | working on that :) |
| 10:43 | justin_smith | also needs a nil check for words |
| 10:44 | justin_smith | also calling last on iterate is a bad idea |
| 10:44 | daGrevis | keys can't be nil |
| 10:44 | justin_smith | right, and without a nil check, it loops forever |
| 10:56 | daGrevis | i don't get why you are passing [] to iterate not chain |
| 10:57 | justin_smith | iterate needs an initial value |
| 10:58 | justin_smith | and the value is what is built up over the calls |
| 10:58 | daGrevis | oh |
| 10:59 | daGrevis | right it makes sense now |
| 10:59 | justin_smith | still a couple of things I need to sort out with that though |
| 11:03 | daGrevis | why did you call last on lazy seq if result from function should be a vector with words? |
| 11:03 | justin_smith | ,(take 5 (iterate #(conj % (rand-int 10)) [])) |
| 11:03 | clojurebot | ([] [2] [2 6] [2 6 1] [2 6 1 7]) |
| 11:04 | justin_smith | ,(last (take 5 (iterate #(conj % (rand-int 10)) []))) |
| 11:04 | clojurebot | [6 9 4 5] |
| 11:04 | daGrevis | right |
| 11:05 | justin_smith | daGrevis: works now https://www.refheap.com/88388 |
| 11:05 | daGrevis | this is a very interesting way to solve this problem |
| 11:05 | justin_smith | I was using pop when I meant peek, d'oh |
| 11:06 | daGrevis | works for sure, thanks |
| 11:06 | daGrevis | now i gotta learn what you know already :D |
| 11:07 | boxed | my version: https://www.refheap.com/88389 |
| 11:08 | justin_smith | ,((fn [c] (last (take-while #(not (nil? (peek %))) (iterate (fn [w] (let [s (peek w) n (rand-nth (get c s))] (conj w n))) [(first (rand-nth (seq c)))])))) {"hello" ["world" "my"] "my" ["baby" "darling"] "baby" ["hello"]}) |
| 11:08 | clojurebot | ["baby" "hello" "world"] |
| 11:08 | justin_smith | ,((fn [c] (last (take-while #(not (nil? (peek %))) (iterate (fn [w] (let [s (peek w) n (rand-nth (get c s))] (conj w n))) [(first (rand-nth (seq c)))])))) {"hello" ["world" "my"] "my" ["baby" "darling"] "baby" ["hello"]}) |
| 11:08 | clojurebot | ["baby" "hello" "world"] |
| 11:08 | justin_smith | ,((fn [c] (last (take-while #(not (nil? (peek %))) (iterate (fn [w] (let [s (peek w) n (rand-nth (get c s))] (conj w n))) [(first (rand-nth (seq c)))])))) {"hello" ["world" "my"] "my" ["baby" "darling"] "baby" ["hello"]}) |
| 11:08 | clojurebot | ["baby" "hello" "my" "baby" "hello" ...] |
| 11:08 | boxed | assuming I understand what we’re doing, which is a pretty big assumption :P |
| 11:08 | justin_smith | ,((fn [c] (last (take-while #(not (nil? (peek %))) (iterate (fn [w] (let [s (peek w) n (rand-nth (get c s))] (conj w n))) [(first (rand-nth (seq c)))])))) {"hello" ["world" "my"] "my" ["baby" "darling"] "baby" ["hello"]}) |
| 11:08 | clojurebot | ["baby" "hello" "world"] |
| 11:08 | justin_smith | ,((fn [c] (last (take-while #(not (nil? (peek %))) (iterate (fn [w] (let [s (peek w) n (rand-nth (get c s))] (conj w n))) [(first (rand-nth (seq c)))])))) {"hello" ["world" "my"] "my" ["baby" "darling"] "baby" ["hello"]}) |
| 11:08 | clojurebot | ["hello" "world"] |
| 11:08 | justin_smith | ,((fn [c] (last (take-while #(not (nil? (peek %))) (iterate (fn [w] (let [s (peek w) n (rand-nth (get c s))] (conj w n))) [(first (rand-nth (seq c)))])))) {"hello" ["world" "my"] "my" ["baby" "darling"] "baby" ["hello"]}) |
| 11:08 | clojurebot | ["baby" "hello" "my" "baby" "hello" ...] |
| 11:08 | justin_smith | anyway, sorry for the spam |
| 11:09 | daGrevis | hmm i start to see the idea |
| 11:09 | boxed | why would you need to check for nil? |
| 11:09 | daGrevis | we pass first word that random as iterate's 2nd arg so we can get rid from special case that's the first iteration |
| 11:10 | justin_smith | boxed: because nil leads to an infinite sequence of nils |
| 11:10 | justin_smith | it is the only stop condition in my version |
| 11:10 | boxed | but there’s no nil in the input data… right? |
| 11:10 | justin_smith | (that is a word with no following words) |
| 11:10 | daGrevis | boxed, thanks! i will look into it as soon as i will understand justin_smith's version |
| 11:10 | justin_smith | boxed: right, but you can have a word that is not an index |
| 11:10 | justin_smith | that gets nil when looked up |
| 11:10 | boxed | aha, gotcha |
| 11:10 | daGrevis | i got it too :D |
| 11:11 | justin_smith | not all words are indexed, in fact, in normal markov-chain lingo, a word that is not a key in the chain map is called a stop word |
| 11:11 | daGrevis | til |
| 11:12 | justin_smith | since it has no possible following word |
| 11:12 | justin_smith | it only exists as an end of statement |
| 11:12 | justin_smith | though, with a more advanced implementation, you can record "." to end a sentence as its own token, and then just never follow up after you reach "." |
| 11:13 | justin_smith | which allows more flexibility (a word has a certain probability of being a stop word this way) |
| 11:13 | boxed | fixed the nil problem: https://www.refheap.com/88389 |
| 11:13 | daGrevis | i wonder what's the best way to stop “loop“ if there's no stop word. you see, i'm building sentences and i don't want sentences that are very long |
| 11:14 | boxed | daGrevis: I have an input param that is a max length |
| 11:14 | justin_smith | well, as I mentioned, you could record end of sentence specially (nil works as well as "." for that, and just stop recurring if you hit that. |
| 11:14 | justin_smith | ) |
| 11:14 | boxed | nice example of using loop-recur this… I managed to get it right on the first try and I’ve never managed to use loop-recur before :P |
| 11:14 | daGrevis | yes, i fully understand justin_smith's one:) |
| 11:15 | justin_smith | then you get statements that are probabalistically in the range of the length of input statements |
| 11:15 | daGrevis | justin_smith, i will have to do that:) |
| 11:16 | boxed | daGrevis: I think mine is a bit simpler to understand… I don’t need two anonymous functions :P |
| 11:19 | daGrevis | im trying to understand it now. give me some time |
| 11:21 | daGrevis | aha, i got it |
| 11:21 | daGrevis | it reminds me of my version i did before https://gist.github.com/5233a7e836f15be227a5 |
| 11:23 | justin_smith | https://www.refheap.com/88388 updated mine with a less verbose version |
| 11:23 | justin_smith | not sure if it is more clear though |
| 11:26 | justin_smith | oh wait, since false is not a valid token in the chain, I can make it much simpler https://www.refheap.com/88388 |
| 11:26 | justin_smith | now only one anon fn |
| 11:28 | daGrevis | here's another my version https://gist.github.com/0de0a4aca40ea10b8edf |
| 11:30 | daGrevis | removed lets that were not really needed |
| 11:30 | daGrevis | https://gist.github.com/d466e39235df87d6d49f |
| 11:30 | daGrevis | what do you think? |
| 11:32 | boxed | is it normal to call the data structure that describes all possible chains “chain”? seems weird.. a chain seems like the output: a list |
| 11:32 | boxed | of course “foo” isn’t super good like in my example code either but still :P |
| 11:34 | daGrevis | well i saw that map like a markov chain because it contains all possible words that may come next and i saw that list like words because it's basically list of words that will make up the sentence and it's no longer a chain because it doesn't have path to next words |
| 11:36 | boxed | a chain is a list of connected metal rings… I think the analogy that [1 2 3] is a chain is pretty solid :P |
| 11:37 | boxed | “sentense” and “word” are specific to this perticular application of markov chains, but not general terms.. so if you use this code for another type of chain generation it’d be very strange |
| 11:38 | boxed | I’ve edited my version to use “next-item” as variable name, I think that makes a lot more sense: https://www.refheap.com/88389 |
| 11:39 | daGrevis | if we call that list a chain |
| 11:40 | daGrevis | how do we call map? |
| 11:40 | boxed | wikipedia wasn’t much help… I don’t like “stochastic-row-vector” for the map :P |
| 11:40 | boxed | I think “state-transitions” is ok? |
| 11:40 | boxed | better than “foo”… actually, even “chains” is pretty ok, because it describes all possible chains |
| 11:41 | boxed | like this: https://www.refheap.com/88389 |
| 11:42 | boxed | changed the funtion to take the state transition map as input, makes more sense |
| 11:43 | boxed | anyway… I’m going for dinner, hope this has helped, I know it has helped me with loop/recur :P |
| 11:56 | sm0ke | hello anyone tried play-clj here? |
| 11:57 | sm0ke | how do i relaunch the game without crashing lein? |
| 11:57 | sm0ke | repl* |
| 13:09 | troutwine | Hi folks, would this be the appropriate channel to ask about emacs setup problems with cider? |
| 13:13 | ybit | troutwine: maybe, but the #emacs channel is active |
| 13:13 | ybit | more so than this one ..on the weekends :) |
| 13:14 | troutwine | ybit: Haha, alright. I'll head there. Thanks. |
| 13:14 | jeremyheiler | there's also #clojure-emacs |
| 13:14 | troutwine | Oh, that sounds dead-on. |
| 14:14 | andyf | Bronsa: Any reason I should avoid trying out the latest t.a(.jvm) for Eastwood? You mentioned there was some performance regression in a recent version, but I haven't been following to see if that has been improved. |
| 14:17 | Bronsa | andyf: there are a bunch of breaking changes in master that I have yet to document on the CHANGELOG |
| 14:18 | andyf | Bronsa: Are there breaking changes in 0.3.0 release relative to 0.2.2 that you recall? |
| 14:18 | Bronsa | andyf: yes but a minor one, :contexts are now namespaced |
| 14:19 | Bronsa | i.e. :statement -> :ctx/statement |
| 14:20 | andyf | Does :statement there mean :statements as in that key in the AST of do expressions? If not that, then I might not be using it in Eastwood anyway right now. |
| 14:20 | Bronsa | andyf: also they now implement a hierarchy so it's wise to replace (= ctx :expr) with (isa? ctx :ctx/expr) |
| 14:21 | Bronsa | andyf: no it's one of the analysis contexts in :env |
| 14:21 | andyf | I'll give 0.3.0 a try and see if anything breaks :) |
| 14:21 | Bronsa | if you're not using it then nothing should break |
| 14:22 | Bronsa | andyf: the performance fix is in 0.3.1-SNAPSHOT, the regression affects 0.2.2, 0.2.3 and 0.3.0 |
| 14:22 | andyf | I'll measure performance to see if it is anything terribly different than previous Eastwood release |
| 14:23 | Bronsa | andyf: not too sure how much it inpacts eastwood but I saw a ~1.5x slowdown in t.e.jvm |
| 15:01 | boxed | update-in not supporting [] as path makes me sad :( |
| 15:04 | boxed | and this makes me even more sad: http://dev.clojure.org/jira/browse/CLJ-373 |
| 15:04 | dbasch | boxed: what would you expect [] to do? |
| 15:06 | boxed | dbasch: without looking it up, can you tell me what you expect for: (update-in {:foo 1} [] #(dissoc % :foo)) |
| 15:07 | dbasch | boxed: it seems you’d want update, which doesn’t exist |
| 15:07 | sritchie | hey technomancy, I was looking at this article: https://devcenter.heroku.com/articles/debugging-clojure |
| 15:07 | sritchie | technomancy: and with lein repl :connect to an endpoint that uses http basic auth, |
| 15:08 | sritchie | it looks like you have to type the password into that string - |
| 15:08 | sritchie | technomancy: what would you think of having “lein repl :connect” prompt for a password if only a username is supplied, like curl? |
| 15:08 | justin_smith | daGrevis: boxed: I realized there was another redundancy in my iterate version, I like the latest version a lot https://www.refheap.com/88388 (now updated with no anonymous functions, and some example output) |
| 15:09 | boxed | dbasch: I don’t know ahead of time how long that path is… so now I have to add an extra if that breaks the symmetry :( |
| 15:10 | nonrecursive_ | hi all - I'm using Emacs and trying to get eldoc working in a clojure-mode buffer after having connected to nrepl with cider-repl |
| 15:11 | boxed | justin_smith: hmm… I’m too unused to functional composition for my brain to parse that :( |
| 15:11 | nonrecursive_ | it seemed like this work with with cider 0.5 (i'm on a 0.7 snapshot now) |
| 15:11 | justin_smith | boxed: total hack version: (update-in [nested] (concat [0] lookup) ...) |
| 15:11 | justin_smith | thus the sequence is always at least of length 1 |
| 15:12 | justin_smith | (because of the added layer of vector, of course) |
| 15:12 | boxed | hah, blech |
| 15:12 | boxed | I think I’ll go with the if :P |
| 15:13 | boxed | justin_smith: but yea, that assymetry in that hack shows why empty path should be supported |
| 15:13 | justin_smith | yeah, I also think it should be supported |
| 15:14 | boxed | at least it’s Principle of Least Surprise |
| 15:17 | justin_smith | boxed: I think in the clojure world, lower complexity of implementation often trumps least surprise |
| 15:18 | boxed | …so a lisp on top of java on top of a JVM favors simplicity of implementation? :P |
| 15:18 | justin_smith | there is no java layer |
| 15:18 | justin_smith | clojure is straight to jvm |
| 15:18 | justin_smith | (with some aspects implemented in java, but the java is not a layer per se) |
| 15:19 | boxed | no java? https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Binding.java <- java! |
| 15:19 | boxed | but yea ok, if you ignore the java there is no java :P |
| 15:20 | justin_smith | it's not a layer |
| 15:20 | boxed | it’s complexity of implementation |
| 15:20 | justin_smith | some of the code is java, others is bootstrapped clojure |
| 15:20 | boxed | anyhow, clojure is clearly built on a mountain of complexity.. but I do understand that Wose is Better |
| 15:20 | boxed | Worse even |
| 15:21 | justin_smith | I didn't say the implementation was free of complexity, I said that often, the principle of least surprise is often trumped by ease of implementation |
| 15:21 | boxed | in this case though, we don’t know what trumped what.. there was a patch, then the issue was closed without ceremony :( |
| 15:22 | sritchie | technomancy: filed an issue on reply, looks like that’s the place where this change would need to occur |
| 15:26 | dbasch | boxed: you’re conflating simplicity of implementation IN the language with simplicity of implementation OF the language |
| 15:27 | dbasch | every technology that’s easy to use has a ridiculously complicated implementation based on geological layers accumulated over decades of technology advances |
| 15:27 | boxed | dbasch: oookey… but implementation IN the language becomes complex because update-in doesn’t handle [], but the implementation OF the language is simpler. So maybe you’re conflating? |
| 15:27 | dbasch | boxed: nobody said implementation OF the language is simple, you are the one who brought up java and the jvm |
| 15:28 | boxed | justin_smith said that the simplicity of implementaton of the language trumps least surprise/correctness |
| 15:28 | boxed | ...sometimes |
| 15:29 | dbasch | boxed: and update-in does handle [], just not in the way you’d like |
| 15:29 | Jaood | justin_smith: there's a java layer for sure, all clojure primitive building blocks are written in Java |
| 15:29 | boxed | dbasch: cop out. Everything “handles” everything if by “handles” you also accept behavior no one ever wants that is totally broken |
| 15:34 | justin_smith | Jaood: clojure has a byte code emitter, it compiles without a java step |
| 15:35 | boxed | and there’s at least been some work to bootstrap those primitives I believe |
| 15:36 | justin_smith | there are at least a couple of pure-clojure-on-jvm type projects in the works |
| 15:36 | justin_smith | (with different goals) |
| 15:43 | boxed | new version of instar that has a special little syntax for dissoc! https://github.com/boxed/instar |
| 15:44 | boxed | it’s like update-in on crack™ |
| 15:44 | AeroNotix | does anyone know if core.clj has ever been ported to common lisp? |
| 15:49 | justin_smith | AeroNotix: no, but racket scheme has most of the clojure features of clojure, and there are various libs that close the gaps |
| 15:49 | justin_smith | by no I mean "I don't know of any", there may be one |
| 15:49 | AeroNotix | justin_smith: "various libs" -- for racket you mean? |
| 15:49 | justin_smith | yeah, to do things like the -> macro |
| 15:49 | AeroNotix | (I'm not really interested in racket (unless you can convince me!)) |
| 15:50 | justin_smith | racket already has immutible collections |
| 15:50 | AeroNotix | So does CL |
| 15:50 | AeroNotix | ~mostly |
| 15:50 | clojurebot | Titim gan éirí ort. |
| 15:50 | justin_smith | it's well designed, and great as a teaching / learning language |
| 15:50 | AeroNotix | It could well be |
| 15:51 | justin_smith | but it isn't an implementation of a standard like common lisp though |
| 15:51 | AeroNotix | sure |
| 15:51 | AeroNotix | TBH I just want to use Clojure with SBCL |
| 15:51 | justin_smith | also, lisp-1, which for some people is a bonus |
| 15:51 | AeroNotix | :) |
| 15:51 | justin_smith | but I know if you like cl enough, you probably don't see lisp-1 as an advantage |
| 15:51 | AeroNotix | lisp1 > lisp2 |
| 15:52 | AeroNotix | I just put up with it in CL |
| 15:53 | ad_latebras | justin_smith |
| 15:53 | ad_latebras | what is your opinion on this whole PC gaming master race thing. |
| 15:53 | AeroNotix | But back to my main point -- there's tonnes I miss from Clojure in CL and vice versa |
| 15:54 | justin_smith | ad_latebras: I have know idea what you are talking about |
| 15:54 | technomancy | supposedly racket's continuations can be used to build something like CL's condition system |
| 15:54 | ad_latebras | justin_smith, well, the idea is that PC gamers are genetically superior to console gamers. |
| 15:54 | ad_latebras | Would you agree? |
| 15:54 | justin_smith | technomancy: continuations are capable of implementing just about anything |
| 15:55 | technomancy | ad_latebras: please don't |
| 15:55 | ad_latebras | technomancy? |
| 15:55 | clojurebot | technomancy is <jweiss> oh man this sucks, why didn't anyone warn me about protocols |
| 15:55 | AeroNotix | +b |
| 15:56 | AeroNotix | technomancy: I don't find I genuinely use conditions all that much. I feel they really shine in a live system that has a human attached to it 24/7 |
| 15:56 | AeroNotix | but that's just like my opinion, man |
| 15:56 | mi6x3m | how would clojure count character occurences for 1 spefic char? |
| 15:56 | mi6x3m | reduce or (count (re-seq ? |
| 15:56 | justin_smith | mi6x3m: frequencies |
| 15:56 | technomancy | ad_latebras: it would be cool if we didn't have to kickban; that's all |
| 15:57 | mi6x3m | justin_smith: I need only 1 of the frequencies :) |
| 15:57 | AeroNotix | mi6x3m: it's the most obvious way to write it |
| 15:57 | justin_smith | ,(get (frequencies "hello world") \l) |
| 15:57 | clojurebot | 3 |
| 15:57 | justin_smith | mi6x3m: well, there is always reduce for that, yeah |
| 15:58 | mi6x3m | good argument, most obvious :) |
| 15:58 | mi6x3m | (inc AeroNotix) |
| 15:58 | lazybot | ⇒ 4 |
| 15:58 | gfredericks | ,(->> "hello world" (filter #{\l}) (count)) |
| 15:58 | mi6x3m | thanks! |
| 15:58 | clojurebot | 3 |
| 15:58 | mi6x3m | ah, sets were functions yes |
| 15:58 | mi6x3m | I always forget |
| 15:59 | gfredericks | reduce is too general for that :) |
| 15:59 | ad_latebras | technomancy, what did I do? |
| 15:59 | justin_smith | gfredericks: yeah, I'd say frequencies if there is no bottleneck, filter/count if you need to get a few more cycles, and finally reduce if the collection is just too big (ie. counting the letter e instances in the kjv) |
| 16:01 | gfredericks | justin_smith: I'm sympathetic to the argument about frequencies doing too much |
| 16:01 | gfredericks | even if in cases where it doesn't make a perf difference |
| 16:01 | gfredericks | not sure I could make a coherent argument about it though |
| 16:02 | AeroNotix | gfredericks: it's less typing |
| 16:02 | AeroNotix | click |
| 16:02 | gfredericks | AeroNotix: I'm more interested in what I have to think about when reading the code than how many characters there are |
| 16:02 | AeroNotix | gfredericks: was kind of a joke :) |
| 16:03 | justin_smith | gfredericks: by the same logic, #{\l} does a bunch of things #(= % \l) doesn't, and they are redundant in this case |
| 16:03 | gfredericks | justin_smith: implementationally, sure, I'm thinking semantically |
| 16:03 | gfredericks | but I agree #{\l} is a bit complicated |
| 16:04 | gfredericks | I think it'd be nice if there were something else |
| 16:05 | gfredericks | again I must emphasize my inability to guarantee coherence here |
| 16:06 | AeroNotix | gfredericks: I'm sure there's enough use-cases behind having an (occurances thing coll) function in core |
| 16:07 | gfredericks | oh I forgot I need to not argue about what should go in core |
| 16:14 | technomancy | ad___latebras: in the past when new people come in and make unsolicited faux-racism remarks to channel regulars it hasn't ended well... merely pattern recognition. |
| 16:14 | ad___latebras | technomancy, oh, o |
| 16:14 | ad___latebras | This is not racism. |
| 16:14 | ad___latebras | In fact |
| 16:14 | ad___latebras | the glorious PC gaming master race is portrayed as a brown man. |
| 16:15 | ad___latebras | And the dirty console peasant as a white man |
| 16:15 | ad___latebras | probably to distance itself from the connotations of racism |
| 16:15 | ad___latebras | technomancy, look: http://segabits.com/wp-content/uploads/2014/04/iconurl.png |
| 16:16 | AeroNotix | can we just ban this troll |
| 16:16 | AeroNotix | it's boring |
| 16:17 | technomancy | AeroNotix: amazing how effective simple pattern recognition can be |
| 16:22 | guestC | hi |
| 16:22 | guestC | anybody alive here? |
| 16:23 | AeroNotix | of course |
| 16:26 | guestC | can anybody explain how does this work? |
| 16:26 | guestC | (defn positive-numbers ([] (positive-numbers 1)) ([n] (cons n (lazy-seq (positive-numbers (inc n)))))) |
| 16:26 | guestC | how can the function exist without parameter vector following its identifier? |
| 16:26 | AeroNotix | guestC: multiple function arities |
| 16:27 | guestC | is that a thing? |
| 16:27 | AeroNotix | that's a thing |
| 16:27 | guestC | ok thank you :) |
| 16:27 | guestC | one more thing |
| 16:27 | AeroNotix | gfi |
| 16:28 | guestC | how would you go about designing stream consumption? lets say i have stream of data coming irregulary and i need to feed it to a function one element after another.. custom lazy sequence? |
| 16:28 | AeroNotix | guestC: take a look at core.async |
| 16:30 | guestC | is that part of the core? |
| 16:30 | augustl | is there any way for cider to auto-detect the port of which a repl is running so I don't have to type in the port number? |
| 16:32 | jeremyheiler | augustl: it does that with .nrepl-port, i believe |
| 16:36 | guestC | AeroNotix: I would have to import something to use core.async right? But in general what you are saying is I should use concurrency, right? |
| 16:36 | AeroNotix | guestC: it's an extra library, you should be using leiningen |
| 16:36 | AeroNotix | guestC: it *sounds* like you should use concurrency, but you didn't really explain fully |
| 16:37 | jeremyheiler | augustl: https://github.com/clojure-emacs/cider/blob/master/nrepl-client.el#L979 |
| 16:37 | guestC | AeroNotix: in java i would be using blocking queue.. not sure how to get that in clojure.. idiomatically |
| 16:38 | AeroNotix | guestC: core.async has channels. Go learn about them |
| 16:38 | AeroNotix | It's kind of like a blocking queue, except a bit different |
| 16:38 | guestC | AeroNotix: ok, thanks for directions ;) |
| 16:38 | AeroNotix | guestC: not a problem |
| 16:38 | justin_smith | AeroNotix: it uses some queues under the hood, but has its own flavor of abstraction over using them |
| 16:39 | AeroNotix | justin_smith: sure, I was intentionally vague in my description so they would go learn |
| 16:43 | augustl | jeremyheiler: ah, I see |
| 16:54 | gfredericks | guestC: lazy seqs aren't a bad way to do it if you can get away with it |
| 16:54 | guestC | i will try that for easy solution before i study upon the async library |
| 17:18 | gfredericks | okay let's pretend I wrote this: https://www.refheap.com/88401 |
| 17:18 | gfredericks | which I did |
| 17:18 | gfredericks | should I have just used clojure.core/locking? |
| 17:22 | justin_smith | well the advantage of an agent is that clojure ensures the sequential state. With locking you need everyone to lock on the same thing if they touch that data. So with a narrow scope of the data, you could simplify things by using locking, but if the data escapes scope, locking is too weak |
| 17:23 | justin_smith | IMO at least |
| 17:25 | gfredericks | the agent doesn't have any data |
| 17:25 | gfredericks | it's just used for locking |
| 17:25 | amalloy | gfredericks: there's at least one race condition in that code, right? |
| 17:26 | amalloy | or wait, you're derefing the promise, not the agent |
| 17:26 | gfredericks | amalloy: not that I kow of |
| 17:26 | gfredericks | cow* |
| 17:27 | amalloy | yeah, i don't see what this is buying you over locking |
| 17:28 | gfredericks | cool that's what I was thinking |
| 17:28 | gfredericks | I did this because I assumed locking was evil |
| 17:28 | amalloy | this also introduces some weird issues, like what if someone calls serialize-on-agent from inside of a dosync, and their func is one that attempts to await-for another agent or something |
| 17:29 | amalloy | i don't know exactly what the failure case is, or even if there is one, but it seems dangerous |
| 17:31 | amalloy | gfredericks: and sure, locking is problematic, but if your solution is to reinvent locking with different primitives what's the point |
| 17:31 | gfredericks | exactly |
| 17:38 | pentlander | how would i go about returning an item from a vector using a closure? for example you have a vec [1 2 3] and a func vec-item that would return 1 on the first call, 2 on the second call etc. |
| 17:39 | brehaut | ~XY |
| 17:39 | clojurebot | Gabh mo leithscéal? |
| 17:41 | brehaut | http://mywiki.wooledge.org/XyProblem |
| 17:41 | brehaut | pentlander: perhaps back up a bit and tell us the problem you are trying to solve rather than asking for the particular solution (because it doesnt sound like a very clojury thing to be doing) |
| 17:42 | mthvedt | pentlander: wrap up a java iterator, but you probably don’t want to do that |
| 17:43 | platz | problem with the XYProblem - does it discourage one from trying to think though a problem? i.e. the initial question exactly is someone trying to exercise their problem solvin skills |
| 17:44 | gfredericks | this is the XYProblemProblem |
| 17:44 | platz | otherwise you just get a post on stackoverflow saying, "please do this for me" |
| 17:44 | brehaut | gfredericks: i think you need an XYProblemProblemAbstractFactoryFactory |
| 17:44 | amalloy | platz: no, it's best to ask both the X and the Y |
| 17:44 | brehaut | Bean |
| 17:45 | platz | amalloy: hrm, that seems to make some sense |
| 17:45 | amalloy | "i want to do X, and i think Y is a good way to do that; how do i do Y?" demonstrates that you've made an effort, and helps the answerer understand your thinking, but doesn't leave them in a "wth why do you want a square wheel" situation like just asking Y would |
| 17:45 | platz | requires an understanding of X though. someone may not even know "the problem they are trying to solve" |
| 17:46 | pentlander | alright well the overall problem is that i have a vec of items ["a" "b" "c"] and i need to output each subsequent item after an event is triggered, so on the first trigger it returns "a" and on the second "b", etc |
| 17:46 | platz | but I may be stretching a bit here |
| 17:46 | gfredericks | pentlander: what sort of events? |
| 17:46 | pentlander | click event |
| 17:46 | amalloy | platz: just ask yourself "why?" four times in a row. isn't that some technique people use? |
| 17:47 | platz | I like your previous answer |
| 17:47 | mthvedt | it’s five whys |
| 17:47 | mthvedt | studies have shown the critical number of whys is 5 |
| 17:47 | amalloy | mthvedt: why? |
| 17:47 | amalloy | (that was the fifth one there, see? it sneaks up on you) |
| 17:47 | mthvedt | amalloy: ask me four more times |
| 17:48 | mthvedt | asketh thou not six whys, nor shalt thou asketh four except that thou proceedeth to five |
| 17:48 | gfredericks | when you ask the fifth why first it kind of messes up the process |
| 17:48 | gfredericks | best to ask them in order |
| 17:55 | mthvedt | can i get a second pair of eyes to look over to the readme for this oss project, before it’s released to the world? |
| 17:55 | mthvedt | https://github.com/mthvedt/qarth |
| 17:59 | dbasch | mthvedt: this method doesn’t do anything: https://github.com/mthvedt/qarth/blob/master/src/qarth/util.clj#L15 |
| 18:00 | mthvedt | dbasch: good catch |
| 18:00 | dbasch | s/method/function of course |
| 18:31 | vimuser2 | Hey there, can someone point me to the direction on how defrecord works? in particular, treating a record as a hash map and adding new fields…from my understanding defrecord creates a class and adds the fields under neath the hood, curious how it implements other fields then |
| 18:32 | Bronsa | vimuser2: it stores them in an internal hashmap |
| 18:32 | Bronsa | ,(defrecord x [a]) |
| 18:32 | clojurebot | sandbox.x |
| 18:32 | Bronsa | (.__extmap (map->x {:a 1 :b 2 :c 3})) |
| 18:33 | Bronsa | ,(.__extmap (map->x {:a 1 :b 2 :c 3})) |
| 18:33 | clojurebot | {:c 3, :b 2} |
| 18:33 | vimuser2 | bronsa: ah, thats what i was guessing. thanks =) |
| 18:51 | vimuser2 | Bronsa: ha, just found defmacro defrecord..lots of little tasty stuff in there =) |
| 18:51 | vimuser2 | well, for a clojure newbie |
| 19:46 | zoldar | Was anyone able to use om 0.6.4 (or any post 0.5.0 for that matter) along with austin repl? there seems to be conflict in requirements for a particular clojurescript version. |
| 20:15 | fifosine | where can I find the source for the mult operator *? |
| 20:16 | TEttinger | fifosine, it's probably an RT function, as in implemented in Java or JS for Clojure or CLJS |
| 20:16 | fifosine | RT? |
| 20:16 | TEttinger | runtime |
| 20:17 | TEttinger | this may be it, https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java#L146 |
| 20:18 | TEttinger | it gets more specific later on https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java#L459 |
| 20:19 | TEttinger | like it has specific versions for doubles https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java#L1379 |
| 20:21 | fifosine | mm |
| 20:49 | gfredericks | I think the CLJS version is a lot simpler, just turning into JS multiplication |
| 21:11 | hellofunk | if I want to apply a sequence to a function, but also need a single additional arg passed to the fn after the sequence, is this really the best way: (apply + (concat (range 5) '(6))) Necessary in Om when the order matters since you are laying out HTML elements |
| 21:16 | justin_smith | well, if the initial collection is a vector, you can at least use conj instead of concat |
| 21:17 | justin_smith | ,(apply + (conj [0 1 2 3 4] 6)) |
| 21:17 | clojurebot | 16 |
| 21:17 | amalloy | hellofunk: yes. or (apply + `(~@(range 5) 6)), but using ` ~ ~@ outside of macros isn't super-popular |
| 21:17 | hellofunk | justin_smith good point though I'm not sure Om's build-all is a vector, I'd have to check |
| 21:17 | justin_smith | amalloy: that's effectively a concat though isn't it? |
| 21:18 | amalloy | sure |
| 21:18 | amalloy | but it's shorter and can be more legible depending on context |
| 21:30 | gfredericks | it's shorter and can be more frightening depending on context |
| 22:13 | cj3kim_ | Hi. I'm tired of using light table for Clojure. Anyone have recommendations on what they use as their IDE? |
| 22:14 | catern | cj3kim_: emacs |
| 22:14 | justin_smith | for an IDE I hear good things about cursive for intellij idea |
| 22:15 | cj3kim_ | emacs sounds good any recommended guides? is onboarding easy? |
| 22:15 | justin_smith | I think learning emacs and clojure at the same time would be a bit rough, but if you already know clojure, emacs may be worth a try |
| 22:16 | justin_smith | it comes with a built in tutorial / docs, but it is ancient, so many things are harder than they would otherwise be because other programs gave different names to things that emacs invented (ie. windows in emacs are frames in modern programs, frames in emacs are windows in modern programs...) |
| 22:16 | radioactiveoctop | hmm i think learning emacs and clojure together would be fine....especially since you have to code in lisp to configure it in the first place |
| 22:16 | justin_smith | radioactiveoctop: if you have a year or two free and not much else to do, sure |
| 22:17 | catern | justin_smith: oh come on |
| 22:17 | bsima | I learned emacs and clojure at the same time. It's worth it. Only took me a few weeks to get the hang of REPL development |
| 22:18 | bsima | and that was only in my free time |
| 22:18 | bsima | I used this a ton braveclojure.com/using-emacs-with-clojure/ |
| 22:18 | bsima | fantastic little intro |
| 22:18 | catern | the entirety of http://www.braveclojure.com/ is great |
| 22:19 | catern | you'd probably want to start from the beginning of it, not that specific section |
| 22:20 | bsima | agreed. That section was just first in my history in Chrome, so I must have used that section most :) |
| 22:21 | cj3kim_ | thanks. |
| 22:22 | cj3kim_ | catern: I will look into it |
| 22:34 | PigDude | do you make things private in your clojure code? |
| 22:34 | PigDude | i see some code that never makes anything private |
| 22:35 | jeremyheiler | i lean towards keeping thigns public, unless they truly are an implementation detail that really should not ever be called ever elsewhere. |
| 22:37 | yedi | been out of the loop for a while |
| 22:37 | yedi | whats the coolest clojure thing you've seen in the last 1-2 months |
| 22:37 | hellofunk | cj3kim_ emacs is probably the most-used IDE for clojure and is very powerful. |
| 22:38 | hellofunk | cj3kim_ here's a cheatsheet of emacs commands useful in clojure work i put together: https://github.com/hellofunk/emacs-clojure-hints |
| 22:38 | fifosine | ,(.indexOf "ABC" \A) |
| 22:38 | clojurebot | #<IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: indexOf for class java.lang.String> |
| 22:38 | fifosine | why doesn't that work? |
| 22:38 | fifosine | String has an indexOf function |
| 22:38 | cj3kim_ | hellofunk: thanks you |
| 22:39 | radioactiveoctop | anyone working on anything cool? |
| 22:40 | jeremyheiler | ,(.indexOf "ABC" "A") |
| 22:40 | clojurebot | 0 |
| 22:41 | jeremyheiler | ,(.indexOf "abc" 97) |
| 22:41 | clojurebot | 0 |
| 22:41 | jeremyheiler | ,(.indexOf "abc" 98) |
| 22:41 | clojurebot | 1 |
| 22:41 | jeremyheiler | fifosine: indexOf takes either a string or an int. |
| 22:41 | fifosine | I have to cast the char as an int? |
| 22:41 | jeremyheiler | or a string.. |
| 22:41 | TEttinger | you can, yeah, or str it |
| 22:42 | fifosine | blech, this is so messy |
| 22:42 | TEttinger | it's the java API for whatever reason |
| 22:42 | jeremyheiler | indexOf doesn't imply a single char |
| 22:42 | arrdem | are there any tools for automated formatting of Clojure forms? I know that core.pprint has one, but it's not especially good at producing human-like code or fast. |
| 22:42 | jeremyheiler | ,(indexOf "abcdefg" "cde") |
| 22:42 | clojurebot | #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: indexOf in this context, compiling:(NO_SOURCE_PATH:0:0)> |
| 22:42 | fifosine | indexOf a character? why not? |
| 22:42 | jeremyheiler | ,(.indexOf "abcdefg" "cde") |
| 22:42 | clojurebot | 2 |
| 22:46 | jeremyheiler | sorry, it can imply a single char, as an int. because java. |
| 22:47 | justin_smith | ,(.indexOf "ABC" (int \A)) |
| 22:47 | clojurebot | 0 |
| 22:54 | sritchie | technomancy: looks like I might have a leiningen 2.4.2 bug |
| 22:54 | sritchie | Caused by: clojure.lang.ArityException: Wrong number of args (3) passed to: server/default-handler |
| 22:54 | sritchie | technomancy: due to this: :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]} |
| 23:02 | lispa | hi all, if someone says they will be sending you a 16 bit unsigned integer what does that mean? |
| 23:02 | lispa | this is an example 088C the person showed me |
| 23:03 | arrdem | &(format "%X" (dec (apply * (repeat 2 16)))) |
| 23:03 | lazybot | ⇒ "FF" |
| 23:04 | arrdem | well whomever they are, they gave you an out of apparent bounds value... |
| 23:06 | lispa | arrdem: kk thanks, but how do i decipher that or start to break it apart, what does 16 bits mean? |
| 23:06 | jeremyheiler | arrdem: a hex digit represents 4 bits, so 16 bits is 4 hex digits |
| 23:07 | arrdem | &16rF |
| 23:07 | lazybot | ⇒ 15 |
| 23:09 | TEttinger | ,(Integer/parseInt "088C" 16) |
| 23:09 | clojurebot | 2188 |
| 23:10 | jeremyheiler | lol |
| 23:10 | TEttinger | ,(Integer/parseInt "FFFF" 16) ; this will work |
| 23:10 | clojurebot | 65535 |
| 23:10 | lispa | thanks guys |
| 23:10 | TEttinger | but |
| 23:10 | lispa | so what would be bit 0? |
| 23:10 | TEttinger | ,(Short/parseShort "FFFF" 16) ; this will work |
| 23:10 | clojurebot | #<NumberFormatException java.lang.NumberFormatException: Value out of range. Value:"FFFF" Radix:16> |
| 23:10 | TEttinger | this will not work* |
| 23:11 | jeremyheiler | if he wants an unsigned int, probably should stick with int |
| 23:11 | TEttinger | so you'll represent these as ints yes |
| 23:11 | jeremyheiler | ints are 32 bits |
| 23:11 | jeremyheiler | signed |
| 23:11 | TEttinger | even though short is a 16-bit type, it has 1 bit uses to tell positive or negative, so... |
| 23:11 | TEttinger | ,Short/MAX_VALUE |
| 23:11 | clojurebot | 32767 |
| 23:11 | jeremyheiler | yes, because it's signed |
| 23:12 | TEttinger | (jeremyheiler, I'm just explaining the terms) |
| 23:12 | jeremyheiler | gotcha sorry |
| 23:13 | TEttinger | there are some tricks here -- if it's strings being sent from an unknown source, you should check that it's within the minimum and maximum of a 16-bit unsigned int. |
| 23:13 | lispa | TEttinger: do you have an article i can read about this |
| 23:14 | TEttinger | ,(Integer/parseInt "-FFFF" 16) ; this will technically bypass the initial check |
| 23:14 | clojurebot | -65535 |
| 23:14 | lispa | in terms of how to convert and read them |
| 23:14 | TEttinger | well how are they being given to you,lispa? |
| 23:14 | arrdem | is there some reason why you would implement a number reader yourself when it's been a solved problem with library code for decades? |
| 23:15 | TEttinger | it's a good question though, strings can be converted by any java program using the standard lib (which clojure uses too) |
| 23:15 | justin_smith | also, if you are getting the data as bytes, there are methods on byte-array to cast the next n bits as a specific primative type |
| 23:16 | lispa | TEttinger: an instrument will post it status to an endpoint |
| 23:16 | justin_smith | lispa: what encoding? |
| 23:16 | justin_smith | lispa: ascii? json? raw bytes? |
| 23:16 | lispa | json string |
| 23:16 | justin_smith | use cheshire |
| 23:17 | TEttinger | $google cheshire clojure |
| 23:17 | lazybot | [dakrone/cheshire · GitHub] https://github.com/dakrone/cheshire |
| 23:17 | justin_smith | https://github.com/dakrone/cheshire |
| 23:17 | justin_smith | heh, beat me to it |
| 23:17 | lispa | but i would like to do it in my mind and understand whats going on first |
| 23:17 | lispa | so in the table it says bit 0 means this |
| 23:17 | lispa | if the value is 1 or 0 |
| 23:18 | TEttinger | lispa, are you just learning how binary works? |
| 23:19 | TEttinger | there may be some better resources |
| 23:19 | lispa | TEttinger: i have an ok understanding |
| 23:21 | TEttinger | well bit 0, which we'll say is the least significant bit, is the same as the "1s place" in normal counting, it just can only go from 0 to 1 instead of 0 to 9. then instead of a 10s place you have a 2s place in binary, after that a 4s place, so now we can do some counting |
| 23:21 | TEttinger | 001 -> equal to 1 |
| 23:22 | TEttinger | 010 -> equal to 2, 011 -> equal to 3 |
| 23:22 | sritchie | technomancy: deleting .repl fixed it |
| 23:22 | arrdem | is there a "standard" file extension for REPL input/output sessions? |
| 23:23 | TEttinger | see how it goes? a 1 in the 1s place is +1, a 1 in the 2s place is +2. starting at 0, 011 is 0 (4s place) + 2 (2s place) + 1 (1s place) |
| 23:23 | kristof | arrdem: .log? |
| 23:23 | arrdem | that'll do. |
| 23:24 | lispa | TEttinger: ahh i get that but then where does the 16 bits come in |
| 23:24 | kristof | arrdem: Be sure to put the date on the file's name, too. I doubt you're saving a REPL output once and never doing the same thing for the same application ever again. |
| 23:25 | arrdem | kristof: oh these aren't real logs... these are examples that are named by the hash of the contents as a Java string. |
| 23:25 | arrdem | order and dates being things IDGAF about |
| 23:25 | kristof | Strike my suggestion, then |
| 23:26 | arrdem | :P |
| 23:26 | TEttinger | lispa, a 16 bit number has 16 places -- I could list them but it's easier just to do ##(map #(bit-shift-left 1 %) (range 0 16)) |
| 23:26 | lazybot | ⇒ (1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768) |
| 23:26 | arrdem | kristof: reworking Grimoire's examples system ATM, just needed a name for when I stashed single examples in files. |
| 23:26 | TEttinger | so normally it is written reversed, but it's different internaly sometimes |
| 23:27 | lispa | TEttinger: so 8204 would get expanded? |
| 23:27 | lispa | or would i ahve to convert that to a 16bit number |
| 23:27 | TEttinger | are you getting it as a string? |
| 23:28 | TEttinger | if you're parsing json, you should use a json lib, but I guess json is all strings anyway (just some are strings inside the json text) |
| 23:29 | lispa | yep getting it as a string |
| 23:29 | TEttinger | so it's most likely you're getting them as numbers in the json, like 8204 instead of "8204" |
| 23:29 | lispa | yea you are right |
| 23:29 | TEttinger | but that 8204 is in a longer string, which starts with { and ends with } |
| 23:29 | lispa | so then i need to figure out what 8204 is in a 16bit form? |
| 23:29 | TEttinger | no, I was a bit confused, it already is |
| 23:30 | TEttinger | 16-bit is how big it can get, unsigned is whether it can be negative or not |
| 23:30 | TEttinger | so you can see this in a simple way in clojure like this: |
| 23:30 | kristof | If it's signed, it can only be as big as 15 bits. |
| 23:30 | TEttinger | ,2r1111111111111111 |
| 23:31 | clojurebot | 65535 |
| 23:31 | kristof | Er, that came out wrong, but hopefully someone will understand what I mean. |
| 23:31 | TEttinger | that's 16 bits in binary |
| 23:31 | TEttinger | and when someone gives you any number, you check if it;s less than or equal to 65535 and greater than or equal to 0 |
| 23:31 | kristof | lispa: Take a systems programming course and learn C |
| 23:32 | TEttinger | if it isn't, it won't fit in a 16-bit unsigned number |
| 23:33 | TEttinger | if you know they're 16-bit unsigned numbers already, you can just ##(Integer/parseInt "8204") |
| 23:33 | lazybot | ⇒ 8204 |
| 23:34 | TEttinger | but really you should use cheshire for reading json, it solved all this already and will probably be faster and more reliable than a new codebase |
| 23:36 | lispa | thanks for all the knowledge |
| 23:50 | TEttinger | no prob |