Fork me on GitHub
#clojure
<
2020-03-12
>
Fred Ross04:03:39

@joshkh I have a Hakyll system I set up a while back that uses Markdown. Then I put it in an S3 bucket as static hosting.

myguidingstar04:03:17

@joshkh if you want a static site generator that is not supported by github pages, you can give gitlab pages a try. Just push the source (markdown?) and have it built and served automatically. I have a gitbook powered site that way https://walkable.gitlab.io

datran04:03:32

What's the workflow for working with a clojure(script) project as far as repls go?

Fred Ross04:03:35

I've definitely thought about using Enlive to transform HTML->HTML and let me write raw HTML but define tags to be transformed like <toc> or similar

datran04:03:55

Cider doesn't seem to like having both a clj and a cljs repl at the same time

cjsauer14:03:04

@U0LE4C7CK switch to your cljs REPL in cider, and try cider-connect-sibling-clj

cjsauer14:03:24

I use this exact workflow with shadow all the time. Fire up shadow with cider-Jack-in-cljs and then cider-connect-sibling to get one of each REPL going.

datran14:03:24

Thanks! I got it working with an cider-jack-in-cljs with shadow, and then cider-connect-clj to an external lein repl, but this sounds better

datran04:03:30

I'm using shadow-cljs for the frontend and lein for the backend

datran04:03:27

cider-jack-in-cljs works like a dream, except it doesn't work for clj

datran04:03:48

and the opposite is true - if I cider-jack-in-clj I can't navigate through my cljs files

datran04:03:38

I've also tried jacking in with a lein repl, then starting a shadow-cljs server in a terminal and then using cider-connect-cljs, but the connect never finishes connecting

datran04:03:25

so I'm curious if anybody does have a workflow to manage this. Right now I'm just trying to work on either frontend stuff or backend stuff and kill the repl when I switch

myguidingstar04:03:32

Did you give cider-connect-cljs the port that shadow cljs printed out?

datran04:03:54

yup! it did want to connect to the lein nrepl server by default, though

myguidingstar04:03:23

I got a project with similar set up, what I did was to jack in clj and connect cljs

myguidingstar04:03:53

With shadow running in a terminal

myguidingstar05:03:48

Sorry Im not using a computer, cant be more specific

datran05:03:20

that's fine! it's good to know that somebody has it working. I think I'll turn on nrepl debugging and see what's going on with the connect

myguidingstar05:03:37

Maybe you should ask in #cider also

absolutejam08:03:42

What's the idiomatic way to handle erroneous states/values in clojure? Coming from Elixir, I'm used to pattern matching and I've seen theres pattern matching in clojure too, but I don't know what the norm is

dominicm08:03:33

Exceptions and nil punning

absolutejam09:03:52

Exceptions even for non exceptional data? I'm thinking more like gracefully handling a 500 from an API call

absolutejam09:03:01

Or just case/cond/multiple dispatch on data shape/values

👍 4
fricze09:03:43

☝️ this one

hindol09:03:51

If you prefer pattern matching, there is https://github.com/clojure/core.match. It is not non-idiomatic.

absolutejam09:03:36

And if this was being passed up a call stack, is there any standard to tag the data structure as a 'bad' return. Eg, simply assoc a :state :error?

absolutejam09:03:46

Or should I just throw/catch?

dominicm09:03:32

The only solutions for error handling in clojure are nil punning and exceptions. The ecosystem provides alternatives, but not ones I'd say are idiomatic.

hindol09:03:32

I think there is no consensus one way or the other. If you look at Pedestal: http://pedestal.io/reference/error-handling - it uses a key :exception. But plain old throw/catch works too.

dominicm09:03:19

Pedestal is special because it's not using normal stack frames, so they're making exceptions work with their concept of a stack frame.

hindol09:03:24

Yeah, I agree Pedestal is special. But defining a bad value as opposed to nil punning works too.

dominicm09:03:45

Spec is the only core thing that does this I think. I'm not sure if it's actually exposed to user space though. Certainly not too much.

mavbozo10:03:05

i just throw (ex-info msg map) and put the information about error in the map . let the caller handle the exception use if/case/cond/multimethod or like pedestal does, core.match

absolutejam10:03:37

Seems like a good solution, thanks. I'm just toying with clojure at the moment and didn't know about ex-info

gekkostate13:03:24

You can also try https://github.com/adambard/failjure for exceptions and error handling. It provides a way to handle exceptions and errors in a very functional way. It works for Clojurescript too.

ro607:03:19

If you're Haskelly-minded

ro607:03:54

In Clojure, the answer is often to think about your (possibly namespaced) map keys, and where they will travel throughout your app. Throwing up the call stack is just one more means of conveyance for a well-structured map.

yuhan08:03:20

What data structure should I use for a collection that has both sequential and associative characteristics?

hindol08:03:54

You mean like an ordered-map?

yuhan09:03:15

oh.. I'll try playing around with that, thanks!

absolutejam09:03:52
replied to a thread:Exceptions and nil punning

Exceptions even for non exceptional data? I'm thinking more like gracefully handling a 500 from an API call

yuhan12:03:42

Is there any theoretical reason why ordered-map library doesn't support nth via the Indexed interface? I noticed the same with clojure's sorted-map, sorted-set and priority-map, even though all of them have well-defined orderings

jjttjj13:03:41

You might already know about this and it doesn't answer your question, but there is https://github.com/clojure/data.avl

yuhan13:03:29

I'll check that out too, thanks!

Alex Miller (Clojure team)12:03:51

Indexed is for the case where you can look up the nth value in better than linear time (hash, etc)

Alex Miller (Clojure team)12:03:00

ordered or sorted would require a linear time walk of the data

Alex Miller (Clojure team)12:03:53

the nth function knows how to do this walk on a sequential (but not Indexed) data structure already

yuhan12:03:24

that's what I thought, but nth already works on seqs in O(n) time - is that an exception to the rule?

yuhan13:03:29

hmm, it also looks like the ordered-map library uses an underlying .order field which is a regular vector, so nth lookups could in fact be near-constant

yuhan14:03:48

oops, I should have known it wasn't that simple - dissoc on an ordered-map leaves nil gaps in the .order vector, which requires a linear traversal to filter out

Alex Miller (Clojure team)13:03:39

then they could implement it (sorted maps are trees)

👌 4
datran14:03:24

Thanks! I got it working with an cider-jack-in-cljs with shadow, and then cider-connect-clj to an external lein repl, but this sounds better

hkjels14:03:13

java -jar Memories.jar -m memories.server
15:39:00.142 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
Exception in thread "main" java.lang.NumberFormatException: For input string: "-m"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.<init>(Integer.java:867)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at clojure.lang.Reflector.invokeConstructor(Reflector.java:305)
        at memories.server$run_server.invokeStatic(server.clj:29)
        at memories.server$run_server.invoke(server.clj:28)
        at memories.server$_main.invokeStatic(server.clj:34)
        at memories.server$_main.doInvoke(server.clj:33)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at memories.server.main(Unknown Source)
make: *** [run-jar] Error 1
I’m trying to make my first uberjar, but trying to run the jar gives me this exception. What does Unknown Source really mean here?

souenzzo14:03:25

@hkjels java -jar Memories.jar already calls memorias.server you are calling (memories.server/-main ["-m" "memories.server"])

hkjels15:03:00

You’re absolutely correct

hkjels15:03:13

thank you!

Eduardo Mata15:03:34

what could be a great library to generate code documentation.

phronmophobic02:03:46

i recently tried out https://github.com/weavejester/codox and was surprised to find out how easy it was to get something reasonable fairly quickly

Ramon Rios17:03:52

Does anyone here has experience with manifold library?

Ramon Rios17:03:32

I have a consume that executes a function when i receive a message from a topic in activemq

(let [handler (fn [msg]
                    (log/info (str "creating customer into " http-url " : " msg))
                    (->> @(add-customer-ror http-url msg)
                         (log/info "returned from server ")))
          stream (m/topic->stream conn topic)]
      (ms/consume handler stream))

Ramon Rios17:03:52

What i'm trying to do now it's to be able to handle errors with it

Ramon Rios17:03:06

My first attempt was zip this, putting into a chain and then do a catch for it

borkdude17:03:28

ah, I'm not too familiar with that part of manifold, only the parts I'm using in yada.

Ramon Rios17:03:44

(let [handler (fn [msg]
                    (log/info (str "creating customer into " http-url " : " msg))
                    (->> @(add-customer-ror http-url msg)
                         (log/info "returned from server ")))
          stream (m/topic->stream conn topic)]
      (-> (ms/consume handler stream)
          ms/zip
          (d/chain (fn [_] (println "Done")) )
          (d/catch (fn [e] (println e "Couldn't consume, restarting ...")))))

Ramon Rios17:03:23

No problem, @U04V15CAJ 🙂 . I appreciate your help anyway. Someone can see this and add something to the discussion

ro607:03:24

Is it behaving differently than you'd expect as written?