Fork me on GitHub
#beginners
<
2017-09-18
>
seancorfield00:09:29

Decomposing the call chain into a series of steps like this has a lot of benefits: you're more likely to separate side-effects from pure computation this way so more of your functions are likely to be pure which makes testing easier -- as well as offering more possibilities of reuse and making it easier to change just one step without changing any other code.

drewverlee02:09:23

@didibus That makes sense to me. I take it from your example you read the section in question. I hope you dont mind that i linked to you comment on the google mailing list for the book. I did it before I caught myself and realized you might not want it me to. 😞. Zach seems a pretty chill guy, i’m not worried about that. I’m just not in the habit of quoting people without asking. I think your observation is a good one and i think Zach would want the feedback. I’m sure he has thought it through it but i’m not fully understanding the idea, sense as you point out, their seem to be alternatives. Maybe the feedback will lead to a concise explanation. BTW i really enjoy this kind of introspection, I get pretty caught up in worrying about choices like this and being able to chat about it gives me lot of insight and confidence. 😄 . Some of these concepts like Dynamic Vars are a bit fringe and haven’t really come up in the toy problems i have solve with Clojure. So

didibus02:09:14

I don't mind. I actually haven't read the book in question. I'm just going off from what you said here. So I can't speak to what Zach mentions, and if it applies or not. This is just my general design recommendation. BTW, if you are interested in this level of design aspects, I highly recommended reading: https://smile.amazon.com/Exercises-Programming-Style-Cristina-Videira/dp/1482227371

drewverlee02:09:52

Thanks. I’ll pick it up. If you didn’t read the book, how did you know the option was turbo-mode?. Is that a common option?

didibus02:09:41

You quoted a snippet of the book earlier that mentioned it.

Simon07:09:42

hi, can anyone advise me on how to write a transformation (s1 s2 s3) => {"s1" s1 "s2" s2 "s3" s3} where in practise the length of the list is not known

Simon07:09:50

furthest I got was : (map-indexed (fn [idx v] [(str "s" idx) v]) lst)

pkova07:09:45

(into {} (map (fn [e] [(name e) e]) lst))

pkova07:09:53

that should work if im understanding you correctly

Simon07:09:51

s1, s2 are maps themselves

Simon07:09:17

(s1 s2 s3) => {"s_1" s1 "s_2" s2 "s_3" s3}

Simon07:09:39

basically i want to go froma list of something complex to a map

Simon07:09:49

so that I can access each one by some unique name

Simon07:09:33

(x1 x2 x3) => {"name_1" x1 "name_2" x2 "name_3" x3}

Simon07:09:22

(into {} (map-indexed (fn [idx v] [(str "screen_" idx) v]) (filter #(= (:type %) "screen") snippets)))

danm09:09:47

(reduce #(assoc %1 (get %2 primary-key) %2) {} items)

danm09:09:02

Where primary-key is your key field

Simon12:09:23

I'm using atom and repl and ran

(use 'figwheel-sidecar.repl-api)
(start-figwheel!)
(cljs-repl)
earlier today. Then I restarted things but I can't rerun the above because portt 3448 is in use. How can I restart the repl in atom

Simon12:09:06

ok, stopped atom, killed java, and restarted

anler12:09:14

Hi all, a newbie question here, what would be the Clojure way of organizing a module tree like this one (Haskell)?

|- Foo.hs
|- Foo/
      |- Bar.hs
      |- Baz.hs
the idea is that Foo contains the api for something that have two different implementations Bar and Baz

gklijs13:09:00

You could use a protocol https://clojure.org/reference/protocols in Foo, and have several implementations of that protocol I think. Never used them myself.

lepistane14:09:56

ok this is wierd

Unhandled java.lang.IllegalArgumentException
   No matching method found: main for class java.lang.Class
but when i list methods in object i have main listed public static how could this be that i cant call something that's available?

hmaurer14:09:40

@lepistane can you share your code please?

lepistane14:09:00

@hmaurer sure. i used https://pdfbox.apache.org/2.0/commandline.html#extracttext saw there is https://github.com/StankovicMarko/pdfboxing wanted to contribute and make function that does exactly that, i dug little bit inside saw i cant make it work, it got too complicated. Then i thought why not just use tool that already exists just make clojure wrapper function around that this is my code

(defn pdf-to-html [pdf-doc]
  (.main ExtractText "-html" pdf-doc))

hmaurer14:09:10

@lepistane main is likely a static method. check this out https://clojure.org/reference/java_interop

lepistane14:09:02

@hmaurer it is static method but when i use (Classname/staticMethod args*) from that link i get

Caused by java.lang.IllegalArgumentException
   No matching method: main

hmaurer14:09:28

@lepistane what about (ExtractText/main ["-html" pdf-doc])?

lepistane14:09:59

@hmaurer

ClassCastException clojure.lang.PersistentVector cannot be cast to [Ljava.lang.String;  pdfboxing.text/pdf-to-html (form-init7626843526357124578.clj:51)

hmaurer14:09:03

@lepistane (ExtractText/main (to-array ["-html" pdf-doc])) ?

lepistane14:09:50

@hmaurer havent tried this one

Unhandled java.lang.ClassCastException
   [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;

manutter5114:09:54

Or maybe just (ExtractText/main "-html" pdf-doc)?

hmaurer14:09:55

doing guesswork here; I am new to Clojure myself. If someone knowledgeable is around please do interrupt me 😄

lepistane14:09:09

@manutter51 it's already like that

hmaurer14:09:17

@lepistane is your pdf-doc a string?

manutter5114:09:34

What’s making this a bit more complicated than usual is you’re trying to call a command line tool as though it were a java lib

lepistane14:09:38

@hmaurer yes

lepistane14:09:41

@manutter51 i know that. the thing is when i tried to make regular function it just went over my head with all document types of pdfbox lib

manutter5114:09:12

Yeah, there’s no reason you should be able to do that as long as you remember it’s expecting command line arguments

manutter5114:09:41

which means pdf-box should be the name of the file you want to convert, I think

manutter5114:09:58

(haven’t done this myself, making educated guesses here)

manutter5114:09:47

Sounds like hmaurer was on the right track with to-array

manutter5114:09:56

but why is it complaining about getting an object where it expects a string?

lepistane14:09:53

i dont know that's why i am asking here xD

manutter5114:09:20

What do you get if you print (class pdf-doc) before the call to ExtractText/main?

manutter5114:09:37

(println (class pdf-doc)) I should say

lepistane14:09:01

got the solution

lepistane14:09:23

(defn pdf-to-html [pdf-doc]
  (ExtractText/main (into-array String ["-html" "MarkoStankovic.pdf"])))

lepistane14:09:13

thank you who ever wrote that function XD ❤️

lepistane14:09:25

thx for help @manutter51 @hmaurer 💋

hmaurer14:09:32

@lepistane ah yeah, that makes perfect sense