Fork me on GitHub
#clojure
<
2016-09-03
>
kingoftheknoll01:09:40

You can test out libraries with lein try easily but is there a way to test a version a clojure not within a project? I’m guessing download and run the jar but I’m curious if people do that.

hans12:09:23

@lambeta Your expression returns a lazy sequence without realizing it. When the later elements are realized outside of the binding established by with-open, the stream will be closed.

hans12:09:45

@lambeta If you want to realize the sequence, use doall inside of the with-open

lambeta12:09:06

@hans I wanna know why the later elements will be realized outside with-open?

hans12:09:56

@lambeta That entirely depends on what you do with the return value of the with-open expression. For example, the repl might want to print it or parts of it.

pesterhazy12:09:35

a lazy-seq is just a java object with a pointer to an anonymous fn

lambeta12:09:14

I just use repl to eval with-open expr, you know, in emacs with ctrl-x e

pesterhazy12:09:50

the scope of with-open, on the other hand, ends when the form is evaluated

pesterhazy12:09:31

this leaves you with a lazy-seq that has not been realized yet but whose underlying stream is closed

pesterhazy12:09:13

the cider middleware realizes the lazy-seq when it tries to pretty-print the results

pesterhazy12:09:32

but that happens to be after execution has left the scope of with-open

pesterhazy12:09:52

does that make sense?

lambeta12:09:17

@pesterhazy does it mean (do (take 2 …)) could not realize all lazy sequences, but doall or dorun could?

hans12:09:22

neither do nor take realize the sequence.

hans12:09:05

take takes as many elements as indicated by the argument, and the good thing about it is that it only does that without realizing the full sequence.

pesterhazy12:09:12

(do (foo)) is exactly equivalent to (foo)

lambeta13:09:36

make sense

jcf15:09:13

Hello everyone! For those who haven't seen this yet, Hashrocket have put out a Websocket shootout with a number of different languages, including Clojure! I'm keen to see if we can make things faster, and hope to maybe learn a thing or two from some of the more experienced Clojure-tuners I know. I've opened this PR with a few tweaks, including some GC tuning (as mentioned by the danger man himself, @alexmiller in https://github.com/hashrocket/websocket-shootout/issues/6). I'd really appreciate any and all input from people with some experience making Clojure fast (correction faster). I know a few names spring to mind, but don't want to call anyone out. Volunteers only please! 😄 The PR can be found here: https://github.com/hashrocket/websocket-shootout/pull/17

jcf16:09:26

The one thing I forgot to mention was Immutant. I wonder if it'd be faster than http-kit.

cptully19:09:05

I have homework problem that I am struggling to wrap my mind around. I’m taking a Java bootcamp at The Iron Yard and we are studying Clojure in parallel (sort of). This particular assignment was withdrawn because too many people were having trouble with it. But the Java version of the assignment was almost too easy so I wanted to tackle the Clojure version. I’ve posted a question to StackOverFlow here:http://stackoverflow.com/questions/39307670/building-a-hashmap-from-an-array-in-clojure/39308362#39308362 And my code is on GitHub: https://github.com/cptully/tiy-homework-collection-katas-clojure The problem I have is trying to take in an array of string values and return a hashmap index where the keys are the first letter of a word and the value associated with each key is an array of strings beginning with that letter. [“aardvark” “people” “apple” “zipper” “pepper”] should produce: { 😛 [“people” “pepper"], :a [“aardvark” “apple”], :z [“zipper”]} This was my first attempt:

cptully19:09:52

I welcome any pointers. One person on Stackoverflow recommended that I could achieve the desired result in one line using reduce, but have yet to puzzle out how.

akiva19:09:11

You don’t need to redo the word-list in the let.

akiva19:09:26

Also, you have to string things together.

akiva19:09:09

The update-in isn’t assigned to anything so the work it does is lost. Same with the assoc.

akiva19:09:12

Everything in Clojure is immutable so changes to index have to be assigned to something.

akiva19:09:06

And yeah, this is definitely something I’d do in a reduce but that can be daunting for someone new to Clojure. You might want to try to work it out in a loop/`recur` and then translate it into a reduce.

akiva19:09:56

Another tip, you don’t need to solve everything in a single function. Anytime a function starts to get gnarly (i.e., multiple, complex calculations within a function), break it out into other functions.

akiva19:09:47

For example, the function in your update-in, I’d put it into its own function and call it from within the update-in.

akiva19:09:02

Hope this helps.

cptully20:09:11

Thanks @akiva I’ll look at it again tonight!

blueberry20:09:21

@cptully: reduce the starting seq by taking each word, taking its first character, converting it to keyword, and conjing the word to the existing value in the map bound to the keyword. the special case is each new keyword, when the value is nil, but that is easily solvable by (get result :a []). i could have written this paragraph as an oneliner, but that is not the point :)

Shantanu Kumar20:09:06

Can anyone suggest a way to describe a boolean option in tools.cli that I can specify as true or false? E.g., --include (true) vs --no-include (false)

gfredericks20:09:22

you're asking for a different name than "include"?

Shantanu Kumar21:09:20

I’m just looking for a way to describe a boolean option that I can specify as true or false on the CLI

Shantanu Kumar21:09:52

Don’t want two flags really

Shantanu Kumar21:09:21

Boolean options with nil or false default work fine, but I’m struggling to override a true default via CLI

cptully21:09:14

@blueberry I am trying to parse through your paragraph…. I have come up with this: (def key-words (map keyword (map #(subs % 0 1) word-list))) => #'tiy-homework-collection-katas-clojure.core/key-words key-words => (:a :a :z :p) from this: word-list => ["aardvark" "apple" "zamboni" "phone”] I have found that a simple call to set will clean up the key-words list, but I am still at a loss for how to build the arrays for each keyword.

blueberry21:09:09

all functions that you need for this are: reduce, get, keyword first, and assoc. in one line. sorry, if i give you any more info, i'll spoil the learning experience.

cptully21:09:39

@blueberry You are most helpful!

blueberry22:09:29

i forgot conj. you need conj to add a word to the list.