#clojure log - Jul 20 2014

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

1: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.

1:05 TEttinger: wenshan, is generator.next a python thing?

1:06 oh I see your question

1:06 I think yes, let me check

1:06 wenshan: yes

1:07 TEttinger: lazyseqs work with nth , for one thing

1:07 wenshan: I'd like to do (while (< curr 1000) (progn ...))

1:07 TEttinger: ,(nth (repeat 10) 99)

1:07 clojurebot: 10

1:08 TEttinger: oh that might be easier with take

1:08 do you have any code now?

1:08 there's also of course loop/recur with an iterator

1:08 wenshan: yes, I have a prime number generator

1:09 trying to get the largest palindrome prime number under 1000

1:09 TEttinger: palindrome being in base 10?

1:09 like 11

1:09 wenshan: yes

1:10 convert the base 10 integer to string, than check whether it's a palindrome

1:10 TEttinger: so your generator returns an infinite lazy seq?

1:10 (doc take-while)

1: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."

1:10 wenshan: I think so, I copied it from http://stackoverflow.com/questions/960980/fast-prime-number-generation-in-clojure

1:11 It has an equivalent python version, which returns a generator (infinite)

1:11 TEttinger: ,(defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) 5))

1:11 clojurebot: #'sandbox/prime?

1:12 TEttinger: ,(take-while #(< % 1000) (filter prime? (range)))

1:12 clojurebot: (2 3 5 7 11 ...)

1:12 TEttinger: ,(count (take-while #(< % 1000) (filter prime? (range))))

1:12 clojurebot: 168

1:13 TEttinger: so there are 168 probably primes under 1000, sound right?

1:13 *probable primes

1:15 ,(last (filter #(.equals (str %) (apply str (rseq (str %)))) (take-while #(< % 1000) (filter prime? (range)))))

1:15 clojurebot: #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Reversible>

1:15 TEttinger: ,(last (filter #(.equals (str %) (apply str (reverse (str %)))) (take-while #(< % 1000) (filter prime? (range)))))

1:15 clojurebot: 929

1:15 TEttinger: there you go

1:15 clojure has to be the best language I know for this kind of development

1:16 (I don't even have a REPL open, and I can still solve the problem -- thanks clojurebot!)

1:17 ,(take-while #(and (> 928 %) (< % 1000)) (filter prime? (range)))

1:18 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: prime? in this context, compiling:(NO_SOURCE_PATH:0:0)>

1:18 TEttinger: haha it unloaded it

1:18 ,(defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) 5))

1:18 clojurebot: #'sandbox/prime?

1:18 TEttinger: ,(take-while #(and (> 928 %) (< % 1000)) (filter prime? (range)))

1:18 clojurebot: (2 3 5 7 11 ...)

1:18 TEttinger: ,(take-while #(and (> % 928) (< % 1000)) (filter prime? (range)))

1:18 clojurebot: ()

1:19 TEttinger: ,(take-while #(and (> % 900) (< % 1000)) (filter prime? (range)))

1:19 clojurebot: ()

1:19 TEttinger: hm

1:22 and to verify,

1:22 ,(clojure.string/join " " (second (split-with #(< % 920) (take-while #(< % 1000) (filter prime? (range))))))

1:22 clojurebot: "929 937 941 947 953 967 971 977 983 991 997"

1:23 TEttinger: wenshan, do you have the gist of it now?

1:31 Aaln: (println "hello everyone")

1: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)

1:31 clojurebot: "11"

1:31 TEttinger: the last base 36 palindrome prime

1:31 under 1000

1:32 ,(Integer/toString (last (filter #(.equals (Integer/toString % 30) (apply str (reverse (Integer/toString % 30)))) (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range))))) 30)

1:32 clojurebot: "131"

1:32 TEttinger: neat

1: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)

1:32 clojurebot: "131"

1:32 TEttinger: hey Aaln

1:32 Aaln: .(println "hello world")

1:32 ,(println "hello world")

1:32 clojurebot: hello world\n

1:32 Aaln: hey @Tettinger

1:32 TEttinger: how goes?

1:33 Aaln: Pretty good, working on a clojure app atm

1:33 What's going on with you?

1:34 TEttinger: just fiddling with clojure while I wait for mono to compile

1:34 Aaln: What is 'mono'?

1:34 TEttinger: it's an implementation of MS .NET libs (and stuff like C#) for other platforms than windows

1:35 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

1:35 Aaln: So .net can compile to *** language?

1:36 TEttinger: no, .NET is just the platform (VM)

1:36 .NET is actually microsoft's one for windows

1:36 mono doesn't do everything .NET does, but it runs almost everywhere

1:37 java and clojure have an edge though because they are easier to get working on android, I would say

1:37 Aaln: Not understanding... Does mono allow you to use .NET on other platforms asides from windows?

1:37 TEttinger: yes

1:37 and .NET is what C# runs on

1:37 Aaln: Awesome

1:38 TEttinger: it would be if it worked!

1:38 Aaln: lol

1:38 Have you used to clojure for android?

1:59 wenshan: TEttinger:Thanks a lot, the isProbablePrime thing looks elegant here. Why did you choose 5 as certainty?

2:00 TEttinger: that's what it had in the stack overflow answer, tbh

2:00 you can probably go lower for under 1000 numbers

2:01 wenshan: I see

2:01 this is really great

2:01 TEttinger: actually let's check now!

2:02 ,(count (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 5) (range))))

2:02 clojurebot: 168

2:02 TEttinger: ,(count (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 2) (range))))

2:02 clojurebot: 169

2:02 TEttinger: ah!

2:03 lower certainties may result in false positives, but 2 is really low

2:03 ,(count (take-while #(< % 1000) (filter #(.isProbablePrime (BigInteger/valueOf %) 9) (range))))

2:03 clojurebot: 168

2:03 TEttinger: so we can be fairly sure there are 168 primes under 1000

2:03 wenshan: makes sense

2: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)))))

2:05 clojurebot: #<ClassNotFoundException java.lang.ClassNotFoundException: clojure.set>

2:06 TEttinger: ,(require clojure.set)

2:06 clojurebot: #<CompilerException java.lang.ClassNotFoundException: clojure.set, compiling:(NO_SOURCE_PATH:0:0)>

2:06 TEttinger: ,(require 'clojure.set)

2:06 clojurebot: #<SecurityException java.lang.SecurityException: denied>

2: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?

2:32 TEttinger: no, not quite. # is a special part of a reader macro that is used for a lot of purposes

2:32 here, it's lambdas

2:32 ,(map inc [1 2 3])

2:32 clojurebot: (2 3 4)

2:32 TEttinger: ,(map #(+ % 1) [1 2 3])

2:32 clojurebot: (2 3 4)

2:33 TEttinger: so #() is a lambda that takes args by number, like %1, %2, %3, and % (with no number)is an alias for %1

2:33 ,(map (fn [n] (+ n 1)) [1 2 3]) equivalent to this

2:34 clojurebot: (2 3 4)

2:34 wenshan: I'm trying to understand it in elisp, I guess it's equivalent to (mapcar (lambda (x) (+ x 1)) '(1 2 3))

2:34 TEttinger: but if you see # elsewhere it depends on what's after it.

2:35 ,(map inc #{1 2 3})

2:35 clojurebot: (2 4 3)

2:35 TEttinger: #{} is a set

2:35 unsorted, but checks for uniqueness

2:35 wenshan: hmm, I see

2:35 TEttinger: and yes, i think you're right about the elisp

2:36 #' is what you mentioned about vars

2:36 ,#'inc

2:36 clojurebot: #'clojure.core/inc

2:36 wenshan: #() is really handy, I like it

2:36 luxbock: http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

2:36 TEttinger: it's great for one-liners, it's why clojure is one of the best lisps for short programs

2:36 luxbock: this is a good resource

2:37 wenshan: thanks :D

2:39 TEttinger: wow, that's really handy luxbock

2:39 I forgot about the #"" regexps, though I use them plenty

2:54 (inc luxbock)

2:54 lazybot: ⇒ 1

2:54 luxbock: yay

2:55 internet points

2:55 TEttinger: clojurebot: symbols |are| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

2:55 clojurebot: Roger.

2:56 TEttinger: symbols?

2:56 clojurebot: symbols are http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

2:56 TEttinger: hm, symbols are also a type

2:56 clojurebot: unlearn symbols |are| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

2:56 clojurebot: In Ordnung

2:56 TEttinger: symbols?

2:56 clojurebot: http://clojure.org/data_structures#toc10

2:57 TEttinger: clojurebot: punctuation |means| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

2:57 clojurebot: 'Sea, mhuise.

2:57 TEttinger: punctuation?

2:57 clojurebot: punctuation means kind of fun

2:57 TEttinger: punctuation?

2:57 clojurebot: punctuation is preferred to a torrent of newlines

2:57 TEttinger: punctuation?

2:57 clojurebot: punctuation means unlearn symbols

2:57 TEttinger: gah

2:58 clojurebot: punctuation |is| http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

2:58 punctuation?

2:59 clojurebot: forget symbols are http://yobriefca.se/blog/2014/05/19/the-weird-and-wonderful-characters-of-clojure/

6: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?

8:35 at21: Hi guys. How to install clojure libraries from clojars (for example https://clojars.org/ring) ?

8:35 I have leiningen installed successfully

8:37 Hi guys. How to install clojure libraries from clojars (for example https://clojars.org/ring) ? I have leiningen installed successfully

8:38 boxed: at21: in project.clj under :dependencies put [thelib “version”] and then run lein

8:38 if you can’t get it to work, put the project.clj on a pastebin and put in the link here

8:40 at21: M-m, thank you. I'll try it

8:48 boxed: Now what? I've just put the library I want into project.clj in .lein/ directory

8:49 jkj: at21: profiles.clj ?

8:49 at21: oh, yeap

8:49 profiles...

8:50 boxed: nono, the project.clj file in your own project

8:53 at21: ok, If I put it in my project file what about other projects?

8:53 and what if I want to use it in REPL?

8:53 boxed: you should add dependencies for a project in that project…

8:54 if you do “lein repl” in the same folder as a project.clj you’ll get the dependencies

8: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?

8:55 boxed: you probably can.. but that is one of the worst things about python so why would you want to? :P

8:55 at21: ))

8:55 why is that?

8:55 boxed: I say this as a full time python code :P

8:55 at21: because it doesn't isolate things?

8:55 boxed: because then you move some code to another machine and it explodes

8:55 yea exactly

8: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?

8:58 boxed: yea

8:58 and it checks that they’re signed properly etc

8: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

8:59 Glenjamin: dependencies are cached locally

9:00 just not in a place they can be depended on implicitly :)

9: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

9:02 at21: don't get it). So I can't store them to further use?

9:03 Glenjamin: they get downloaded to ~/.m2

9:03 at21: great

9:03 that's what i've been asking

9:04 so that means I can use them whenever I want without the internet (if they are downloaded already) by just pointing it in :dependencies?

9:05 Glenjamin: yes

9:05 at21: Oh, great. Big thanks to <boxed> and <Glendjamin>

9:06 boxed: np

9:19 daGrevis: hi! i know there's lein repl. is there anything more advanced with syntax highlight and auto-complete?

9: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)

9:25 daGrevis: justin_smith, but is there anything that's editor agnostic?

9:28 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?

9:29 i mean exactly... i can't create a temporary variable and store things i will return later

9:29 i can't find anything like yield in python too so that's out

9:30 nathan7: daGrevis: .WHAT DO YOU MEAN?

9:30 err

9:30 sorry for caps

9:30 daGrevis: (let [x (inc y)] ...)

9:31 daGrevis: tahdah, temp variable

9:31 daGrevis: hmm how could i explain it better without you doing in my place :D

9:31 nathan7: daGrevis: `let` creates local variables

9:31 daGrevis: nathan7, right, but i can't change it no?

9:31 nathan7: Correct, but you can make new things based on it

9:31 (let [x (inc x)] …)

9:31 that's basically x += 1

9:32 daGrevis: https://gist.github.com/e17730a0d1c4bee11718

9:33 nathan7: Try `for` instead of dotimes

9:33 and no need to turn chain into a seq beforehand, by the way

9:33 daGrevis: right list comp!

9:34 nathan7, chain's a map

9:34 nathan7: daGrevis: rand-nth should turn it into a seq by itself I think?

9:34 daGrevis: rand-nth won't work on map, only seq

9:34 Glenjamin: $source rand-nth

9:34 lazybot: rand-nth is http://is.gd/HVnhk6

9:34 nathan7: ,(rand-nth {:a :b})

9:34 clojurebot: #<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap>

9:34 nathan7: :(

9:34 daGrevis: told ya :)

9:34 nathan7: silly

9:34 Glenjamin: it does this: (nth coll (rand-int (count coll))))

9:34 nathan7: yeah

9:35 Glenjamin: which makes a whole bunch of assumptions

9:35 nathan7: mhm

9:35 yay dynamic typing

9:35 daGrevis: :)

9:39 i'm not sure for will be the best solution there

9:40 basically i have markov chain in format of {:word [:following :words] :word2 [...]}

9:40 and i want to choose key, then choose value of that key and repeat it 2 to 5 times

9:42 Glenjamin: something like (mapcat #(random-sample (val %)) (random-sample words))

9:42 daGrevis: i'll just try recur it

10:16 i wrote what i wanted

10:16 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 i expressed it already

10:27 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 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 it doesn't "iterate through" anything

10:30 it repeatedly takes some action to build a result

10:31 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 if i understand correctly

10:37 boxed, https://gist.github.com/41dbe86764e19228bc32

10:37 justin_smith: daGrevis: my version, untested because I don't have the chain map

10:37 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 ah

10:40 daGrevis: here's better data set https://gist.github.com/94ec78b417a40c567d05

10:41 not much better thought :)

10:42 justin_smith, it throws exception about not being able to pop empty vector

10:43 justin_smith: yeah

10:43 working on that :)

10:43 also needs a nil check for words

10:44 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 and the value is what is built up over the calls

10:58 daGrevis: oh

10:59 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 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 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 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 it only exists as an end of statement

11:12 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 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 )

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 aha, i got it

11:21 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 not sure if it is more clear though

11:26 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 now only one anon fn

11:28 daGrevis: here's another my version https://gist.github.com/0de0a4aca40ea10b8edf

11:30 removed lets that were not really needed

11:30 https://gist.github.com/d466e39235df87d6d49f

11:30 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 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 “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 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 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 I think “state-transitions” is ok?

11:40 better than “foo”… actually, even “chains” is pretty ok, because it describes all possible chains

11:41 like this: https://www.refheap.com/88389

11:42 changed the funtion to take the state transition map as input, makes more sense

11:43 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 how do i relaunch the game without crashing lein?

11:57 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 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 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 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 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 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 technomancy: and with lein repl :connect to an endpoint that uses http basic auth,

15:08 it looks like you have to type the password into that string -

15:08 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 thus the sequence is always at least of length 1

15:12 (because of the added layer of vector, of course)

15:12 boxed: hah, blech

15:12 I think I’ll go with the if :P

15:13 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 clojure is straight to jvm

15:18 (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 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 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 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 ...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 (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 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 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 ~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 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 I just put up with it in CL

15:53 ad_latebras: justin_smith

15:53 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 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 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 but that's just like my opinion, man

15:56 mi6x3m: how would clojure count character occurences for 1 spefic char?

15:56 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 (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 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 even if in cases where it doesn't make a perf difference

16:01 not sure I could make a coherent argument about it though

16:02 AeroNotix: gfredericks: it's less typing

16:02 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 never makes jokes on IRC

16:03 gfredericks: justin_smith: implementationally, sure, I'm thinking semantically

16:03 but I agree #{\l} is a bit complicated

16:04 I think it'd be nice if there were something else

16:05 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 This is not racism.

16:14 In fact

16:14 the glorious PC gaming master race is portrayed as a brown man.

16:15 And the dirty console peasant as a white man

16:15 probably to distance itself from the connotations of racism

16:15 technomancy, look: http://segabits.com/wp-content/uploads/2014/04/iconurl.png

16:16 AeroNotix: can we just ban this troll

16:16 it's boring

16:17 technomancy: AeroNotix: amazing how effective simple pattern recognition can be

16:22 guestC: hi

16:22 anybody alive here?

16:23 AeroNotix: of course

16:26 guestC: can anybody explain how does this work?

16:26 (defn positive-numbers ([] (positive-numbers 1)) ([n] (cons n (lazy-seq (positive-numbers (inc n))))))

16:26 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 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 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 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 which I did

17:18 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 IMO at least

17:25 gfredericks: the agent doesn't have any data

17:25 it's just used for locking

17:25 amalloy: gfredericks: there's at least one race condition in that code, right?

17:26 or wait, you're derefing the promise, not the agent

17:26 gfredericks: amalloy: not that I kow of

17:26 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 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 i don't know exactly what the failure case is, or even if there is one, but it seems dangerous

17:31 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 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 studies have shown the critical number of whys is 5

17:47 amalloy: mthvedt: why?

17:47 (that was the fifth one there, see? it sneaks up on you)

17:47 mthvedt: amalloy: ask me four more times

17:48 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 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 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 ,(defrecord x [a])

18:32 clojurebot: sandbox.x

18:32 Bronsa: (.__extmap (map->x {:a 1 :b 2 :c 3}))

18:33 ,(.__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 Bronsa: ha, just found defmacro defrecord..lots of little tasty stuff in there =)

18:51 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 this may be it, https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java#L146

20:18 it gets more specific later on https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java#L459

20:19 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 ,(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 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 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 and that was only in my free time

22:18 I used this a ton braveclojure.com/using-emacs-with-clojure/

22:18 fantastic little intro

22:18 catern: the entirety of http://www.braveclojure.com/ is great

22:19 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 catern: I will look into it

22:34 PigDude: do you make things private in your clojure code?

22:34 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 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 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 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 Caused by: clojure.lang.ArityException: Wrong number of args (3) passed to: server/default-handler

22:54 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 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 * arrdem slaps himself a few times, remebers it's Sunday and stops caring

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 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 ,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 * arrdem didn't mean to be that snarky

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 * arrdem remebers being awestruck at the ASCII->INT algorithm

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 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 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 so in the table it says bit 0 means this

23:17 if the value is 1 or 0

23:18 TEttinger: lispa, are you just learning how binary works?

23:19 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 001 -> equal to 1

23:22 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:22 * arrdem knows of no such thing

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 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 or would i ahve to convert that to a 16bit number

23:27 TEttinger: are you getting it as a string?

23:28 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 16-bit is how big it can get, unsigned is whether it can be negative or not

23:30 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 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 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

Logging service provided by n01se.net