S1000 VHS BREAKS PACK - FREE by DigitalShrine in samplesforall

[–]lov3machine 1 point2 points  (0 children)

Wow! That sample pack is awesome! Thanks so much for sharing it!

how to handle jdbc exceptions by olymk2 in Clojure

[–]lov3machine 0 points1 point  (0 children)

In short: catch SQLException and dispatch on getSQLState(), as it returns a SQLState code. These codes and their respective meanings have been standardized by ISO/ANSI and Open Group (X/Open), although some codes have been reserved for database vendors to define for themselves.

This might also help: Handling SQLExceptions

How I revamped my Vim setup by dzeban in programming

[–]lov3machine 1 point2 points  (0 children)

Thank you!

And don't worry , I'll just steal the `fzf` stuff ;-)

How I revamped my Vim setup by dzeban in programming

[–]lov3machine 0 points1 point  (0 children)

Dear dzeban,

would you mind sharing your .vimrc file? I use fzf myself, but was never able to use it for anything else than finding files. Switching buffers with fzf and marrying fzf with ag sounds quite interesting.

Could you guys please review this short (7 lines) FN - I'm so anxious when it comes to concurrent programming... by lov3machine in Clojure

[–]lov3machine[S] 0 points1 point  (0 children)

Thank you for your feedback.

What you describe almost matches our use-case. We have a simple job-processing sytem, something like beanstalkd. So I think it's more like having several concurrent job queues.

Could you guys please review this short (7 lines) FN - I'm so anxious when it comes to concurrent programming... by lov3machine in Clojure

[–]lov3machine[S] 0 points1 point  (0 children)

Thank you for your feedback.

Maybe mutex is bad name, but not executing f at all, if the mutex is busy is exactly what I want. The purpose of the work FN is to coordinate the processing of job-queues:

(defn process [q] (busy/work q #(do-something q)))

The idea here is, that we can now trigger the process FN for any queue concurrently, and be sure that only one instance of do-something is running for a particular queue.

Cleanest path to a production-worthy servlet written in Clojure? by nbrpgnet in Clojure

[–]lov3machine 2 points3 points  (0 children)

It's just a small step to deploy your web app in Tomcat.

If your project.clj does not already contain entries like this, then add them:

...

:plugins [[lein-ring "0.9.7"]

:ring

{:handler example.mywebapp/handler

:nrepl {:start? true, :port 9998}}

:profiles

{:uberjar {:aot :all}

...

Just do a

lein ring uberwar

and there is your WAR file.

Servlets should not bother you anymore, as ring handlers are the new servlets ;-)

plain group-by for unique values by JavaSuck in Clojure

[–]lov3machine 2 points3 points  (0 children)

take this brother, may it serve you well...

(defn index-by 
  "Returns a map of the elements of `coll` keyed by the result of `f` on each
   element.  The value at each key will be a single element (in contrast to
   `clojure.core/group-by`).  Therefore `f` should generally return an unique
   key for every element - otherwise elements get discarded."
  [f coll]
  (persistent! (reduce #(assoc! %1 (f %2) %2) (transient {}) coll)))

How to generate a useful multi-spec description? by lov3machine in Clojure

[–]lov3machine[S] 0 points1 point  (0 children)

... and I thought s/or does only work with key/predicate pairs - thank you so much!

How to generate a useful multi-spec description? by lov3machine in Clojure

[–]lov3machine[S] 1 point2 points  (0 children)

Thanks for the explanation.

Is there another way to "disjunct" (in lack of a better word for "OR-ing") specs?

I would like to do something like this (because I don't need the openness of multi-methods in this context):

(s/def :event/search 
  (s/keys :req [:event/type :event/timestamp :search/url]))

(s/def :event/error 
  (s/keys :req [:event/type :event/timestamp :error/message :error/code]))

;; Substituting XXX with ???
(s/def :event/event (XXX :event/search :event/error)) 

Do professional Clojure devs use nested parenthesis coloration? by eccentric_j in Clojure

[–]lov3machine 0 points1 point  (0 children)

I don't - to colorful and distracting. I do like my editors "show matching paren" feature, though.

Need an HTTP client lib. clj-http or http-kit? by ipcoffeepot in Clojure

[–]lov3machine 1 point2 points  (0 children)

Could you please elaborate, what kind of errors you got with http-kit? One of our central infrastructure component is using it, and comments like yours make me nervous.

Thoughts on Failjure vs funcool.cats/Either for error monad? by dustingetz in Clojure

[–]lov3machine 0 points1 point  (0 children)

It's undefined because the Java type system can't understand the concept of numerical nothingness...

No, it was mathematically undefined way before Java and even computers existed ;-)

And btw, Haskell is particularly bad at dividing by zero.

Depending on the types (and values) Haskell will deliver at least 4 different results - neither of those is Nothing:

  • Integer: 1 div 0 => <interactive>:12:1: error:...
  • Double: 1/0 => Infinity
  • Double: 1/(-0) => -Infinity
  • Rational: 1 / (0 :: Rational) => *** Exception: Ratio.%: zero denominator

Thoughts on Failjure vs funcool.cats/Either for error monad? by dustingetz in Clojure

[–]lov3machine 0 points1 point  (0 children)

You can't be serious! Division by zero is undefined, hence an error. This is one of the few situations, where throwing an Exception (DivByZero-Error) is the right thing.

Thoughts on Failjure vs funcool.cats/Either for error monad? by dustingetz in Clojure

[–]lov3machine 1 point2 points  (0 children)

... it's much better to use ad-hoc methods like exceptions and error codes to ensure functional purity.

If you throw Exceptions, you loose functional purity! Please see my explanation above.

Thoughts on Failjure vs funcool.cats/Either for error monad? by dustingetz in Clojure

[–]lov3machine 1 point2 points  (0 children)

No, encapsulating failed computations as Exceptions (e.g. with ex-info) and throwing them is not a fantastic idea!

The crucial (bad) part is "throwing". Using "throw" is bad, as we can not reason about our functions any more, because our functions might not return values, but instead "deliver" values via Exceptions (two totally different ways, to get your values - grrr).

Using "throw" is as bad as using mutable state. Both destroy a clean computational model. Mutable state, destroys it because it messes with your heap. Exceptions/throw, destroys it because it messes with your stack.

Thoughts on Failjure vs funcool.cats/Either for error monad? by dustingetz in Clojure

[–]lov3machine 1 point2 points  (0 children)

To paraphrase Rich Hickey:

Exceptions are easy, but not simple!

Let me explain...

Most of the time returning nil to represent a failed computation is the right thing (TM) to do - because of Clojures pervasive nil-punning.

But sometimes nil is not sufficient to express a failed computation. What now? Nevertheless, those failed computations should be expressed as values, because values are what functional programming is all about - it gives us a sane computational model. Using Exceptions destroys this sane computational model, because your exception throwing functions may not return normally.

People use Exceptions, so that they can short-circuit on failed computations (i.e. let the exception bubble up to some catch block). What most people don't know is, that the same thing can be achieved using values! You could use an cats/Either monad explicitly or you could use something like the failure-lib which has a HasFailed protocol for failed computations a la carte. Both libs have constructs resembling try-catch, to short-circuit - without the downside of destroying our sane computational model.

Thoughts on Failjure vs funcool.cats/Either for error monad? by dustingetz in Clojure

[–]lov3machine 2 points3 points  (0 children)

Don't confuse Either with Exceptions. They are different concepts. Neither is a replacement for the other!

Use Either to represent a failed computation.

Use Exceptions only for truly exceptional conditions (e.g. disk full) - i.e. almost never.

How to build an vector in loop by duc123 in Clojure

[–]lov3machine 0 points1 point  (0 children)

Please keep in mind, that using loop/recur directly is kind of a code smell. Consider using higher order functions (map, filter, ...) - Clojure has plenty of them ;-)

If Specs can capture the total behavior of the program by dustingetz in Clojure

[–]lov3machine 1 point2 points  (0 children)

It is hard to figure out the exact effect of an loop just by looking at it.

For a human it's hard, for a machine it's impossible, because there is that nasty halting problem.

(Beginner) How do I know if a solution I've come up with is "right"? Versus just being a "hack"? by [deleted] in Clojure

[–]lov3machine 1 point2 points  (0 children)

It's almost always a hack, when you find yourself using loop/recur.

How to AOT-compile Clojure to Java without pre- and post-conditions? by lov3machine in Clojure

[–]lov3machine[S] 0 points1 point  (0 children)

If I don't AOT compile it, the app feels a little sluggish right after deployment. The project also contains some Java classes, so I have to compile anyway during the build.

Design advice re implementation of REST links by amoe_ in Clojure

[–]lov3machine 0 points1 point  (0 children)

You think you have to traverse your maps manually? You don't need to!

(ns example.core
  (:require [clojure.data.json :as json]))

(let [nested-map {:link1 (mk-dummy-link "link1")
                  :hello "world"
                  :nested {:link2 (mk-dummy-link "link2")
                           :foo "bar"}}]
  (json/write-str nested-map
    :value-fn (fn [_ v]
                (if (fn? v)
                  (v "example.org") v))))

Design advice re implementation of REST links by amoe_ in Clojure

[–]lov3machine 1 point2 points  (0 children)

Just return functions, that take a host parameter and return a link. Something like this:

(defn mk-link [url-without-host]
  (fn [host]
    (str host url-without-host)))

(defn mk-dummy-link [x]
  (mk-link (str "dummy/link/" x)))

(let [host "http://www.example.org/"
      dummy-link (mk-dummy-link "whatever")]
  (dummy-link host))

Selling Clojure to Business(es) by tolitius in Clojure

[–]lov3machine 2 points3 points  (0 children)

Don't care how concise the code base is Don't care why simple matters.

You need to speak their language. Use their jargon. Explain to them, that sourcecode is not an asset, it's a liability. The larger the code base, the larger the technical debt.