This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-08
Channels
- # admin-announcements (3)
- # alda (2)
- # beginners (66)
- # boot (54)
- # cider (21)
- # clara (1)
- # cljsfiddle (32)
- # cljsrn (9)
- # clojars (4)
- # clojure (164)
- # clojure-dusseldorf (4)
- # clojure-japan (2)
- # clojure-norway (1)
- # clojure-russia (76)
- # clojure-sg (8)
- # clojurescript (19)
- # core-async (1)
- # core-typed (1)
- # cursive (6)
- # datomic (1)
- # editors (48)
- # hoplon (20)
- # immutant (2)
- # jobs-discuss (6)
- # ldnclj (1)
- # om (82)
- # onyx (6)
- # parinfer (11)
- # proton (2)
- # re-frame (113)
- # reagent (17)
- # testing (11)
- # untangled (11)
- # vim (4)
- # yada (38)
my concrete issue at hand is that i need to have something similar to a connection pool
@lmergen: You might like to read/skim this: http://stuartsierra.com/2013/03/29/perils-of-dynamic-scope
FWIW, I used it pretty often when I used Common Lisp, but never yet in Clojure... except when experimenting with error-handling. (Not that this is evidence one way or the other, since you may have a use-case I haven't had.)
> By all means, provide the functions to acquire and dispose of resources, but then let the application programmer decide what to do with them. Define API functions to take the resource as an argument.
in my case, that would mean exposing the connection pool explicitly to all ring
handlers that use the database? is that correct.. ?
or i would have to write a ring middleware that automatically acquires and releases a connection
hey @lmergen the first one- db functions, called from handlers, should take a pool as an argument and get and release connections around query execution through the pool. So handlers should be able to "see" the pool. How do they do that- Stuart's piece is part of the story of a pattern for managing this tree of state- server -> handlers -> db pool- that also enables a fluid repl workflow: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded
Yes, it is
The company is now called Cognitect, and they are behind Clojure and Datomic
that's pretty awesome... i really want to use Datomic, but it seems like a really big risk
you don’t need dynamic vars to have a connection pool. I personally use component for that.
is there a sort of printline that i can see in the browser for .clj files/ the backend/
@lmergen bkamphaus from the Datomic team at Cognitect is active on the #C03RZMDSH channel
@krchia: it depends on the web framework, but usually you return a string in the :body of a response object. Using println or similar will write to your application logs or to a similar file on your server- not visible to users
so, in languages such as Erlang and Haskell, pattern matching is a big thing... in Erlang/Elixir, it's even used for "error propagation" -- what you see a lot, for example, is this pattern:
{:ok, value} = doStuff()
which will raise an error if the the result is not :ok ... is there something as simple and pragmatic for Clojure?so the key here is that assignment of value
, and the check for :ok
is both happening at the same time
By raising an error, you mean throwing an exception, @lmergen ? I am under the impression in Clojure exceptions tend to be avoided, since they break function purity.
yes, I'm not sure what the best approach is in Clojure.. it feels like it suffers from the same problem as Haskell, that is: there are too many ways to do it
Often, nil
is returned on error. I am not sure nil punning is the best solution (stuff might fail silently if you don't check), but it seems to be most common solution.
There’s a pretty good library you might find interesting: http://docs.caudate.me/hara/hara-event.html
@lmergen the mindset is a little different, and there is something of a paradox of choice. pattern matching is a specific instance of a protocol- not a clojure protocol but the manner of callers engaging with callees. in other languages, support for specific protocols is part of the language. the language is opinionated about protocols to use. As a lisp, clojure is somewhat less opinionated. Within the constraints of syntax, you can build that protocol if you're interested- for matching, see an old example called matchure: https://github.com/dcolthorp/matchure
but I'm not really looking for a when-match
, I'm looking for a assign-when-matcher-or-raise-error
or something
this might be a good place for a macro, but i think that's just my Clojure noobiness that thinks "oh yes, let's use a macro to solve this!"
right- in jvm-hosted languages, the callee can throw an exception; if you're returning a tuple/Maybe-style you're doing so to avoid the exception handling machinery
Curious what you mean?
That’s fair. It’s certainly not idiomatic clojure.
anyway, guess I should just get it out of my head i can do erlang-style pattern/error matching
the error model is what's most different, you do have to think about error handling differently
well, there are lots of ways of doing it; in Haskell you can rely on the type system; in Erlang you can rely on the runtime
you do need to be more mechanical in Clojure, which can then yield insights around data flow
It really depends on how you want to handle that error (i. e. some errors aren't meant to be handled and should be spotted by the developer ASAP). If you're expecting an error somewhere you either have to explicitly indicate what to do; you could wrap that into a higher-order function probably for more reusability. I haven't seen many use cases for exceptions in Clojure except for Java interop. But maybe I just haven't seen too much of it yet %)
well, this for example is from our email provider, in what i consider to be very rare cases, sending an email might fail
well- wrt sending an email, it depends on whether that failure impacts the rest of the system, it depends on who cares
Then I'd probably stick with a higher-order function that wraps the action and either returns its result only (assuming :ok
) or logs the error into the monitoring system and just carries on. Without any feedback to the caller.
The fn?
fn tests if a value is a Fn