Fork me on GitHub

What does the extension .cljc tend to mean?

Matti Uusitalo12:01:14

The source is intended to work in clojure and clojurescript both.

Alex Miller (Clojure team)12:01:32

the extra "c" stands for "common"


Ok thank you, very interesting


is there a way to indent and lint the clojure code which read from stdin and write to stdout ?


@nxtk seems interesting, but how can i do indentation read from stdin -> stdout ?


maybe i can skip linter for now

Markus Kiili14:01:06

Hi. How do you actually deploy a Ring app on a server? In other words, how to deploy an uberjar.

Markus Kiili14:01:50

I have been able to make the jar run on my linux server. Just wondering what if there is some problem or the whole operating system reboots? How to make it so that it starts up again.

Matti Uusitalo15:01:45

You can set up a system service which keeps it up. Checkout systemd, systemctl etc

Matti Uusitalo15:01:23

Assuming your linux uses systemd


I am struggling a bit with the anonymous functions. I am trying to make two identical functions, the one with # works, but the one using the longer notation lambda (fn) doesnt.


(defn inc-maker
  "Create a custom incrementor"
  #(+ % inc-by))


(defn inc-maker2 “Create a custom incrementor” [inc-by] (fn (+ inc-by)))


you did not tell the longer form about its arguments

👍 4

(defn inc-maker2 
  "Create a custom incrementor"
  (fn [inc-by] (+ inc-by)))


Thanks, that one works.


see, you want to have a function that accepts an argument x and increments it by inc-by


in your short form, your x is %


in your long form you have nothing to do the same job as % in your short form, get it?


and, inc-by is the argument to inc-maker2 function, not to your resulting function


Hey, I just trying out the re-frame templete with cider. Did lein new re-frame yeah +cider and tried to jack in, but got the following error

Execution error (ExceptionInfo) at shadow.cljs.devtools.server.runtime/get-instance! (runtime.clj:11).
missing instance
lein dev runs fine


cider-jack-in-cljs btw


it worked fine for me. Did you get an option for which build to use and you chose app?


also, this project has two build systems. I saw that in lein it just calls out to shadow so when CIDER asks me which build it should use i just said shadow


and you're receiving that error message after choosing shadow and then app as the build?


cider somehow infers that it's shadow so only asks me for the build type


yeah. in the dir-locals file it sets the preferred build tool


nevermind now I see what you meant, I thought you meant the CLJS repl type. That was actually the error.


In figwheel you still choose lein


Wasn't used to that


awesome! glad its working


Hello, I'm messing around with deftype and wondering if it's possible to create a variable that all the methods will have access to. Basically I'd like it to look something like this:

(deftype ManagementApi [endpoint]
  ;; (let [api (make-api endpoint)]
  (get-connection [this params]
    ;; Do something with the outer api
  (delete-connection [this params]
    ;; Do something with the outer api
Where both methods will have access to that api variable (not sure what the syntax would be)


i don't believe so. What you can do is pass that in and make a function that takes the endpoint and returns the deftype with both items bound. Ie, (defn management-api [endpoint] (->ManagementApi endpoint (make-api endpoint)))


Ahhh, that would be a good approach. Much more functional 🙂 Thanks @dpsutton!


I have a somewhat conceptual question. So I come mostly from a Ruby background where a lot of ORMs are available. As far as I noticed, Clojurians do not seem to like ORMs. So how do you structure your persistency logic then? Do you just write specialized SQL queries for each API request? Do you have open source examples how you structure your database logic where there are more than one or two tables?


Or is it possible to have a somewhat generic set of functions which you use to build the persistency logic? When I try thinking about how this could be achieved, it seems really hard e.g. when it comes to joining tables or other complex queries


@christian.paling For basic CRUD, you can just read and write hash maps, and update/delete by example (using a hash map) against the database using next.jdbc (or or a few others). For more than simple CRUD, you can either write the SQL (and use any of those JDBC wrappers) or you can look to some of the DSLs out there like HoneySQL, Walkable, etc.


Thanks for the links ! I will take a look at them ! So people do not use something like lightweight repository objects or anything. But actually just write the SQL queries they need


I‘m sorry if these questions sound confusing, I‘m just used to having something like User.where(...).joins(...)


And whenever I implement a system, even if I don‘t use a ORM library, I somehow have the urge to abstract my persistency logic, i.e. implement my own mini ORM


Clojure has no objects, just bare data.


But that User.where(...).joins(...) maps over to something like HoneySQL's DSL: (-> (select :a) (from :user) (where ...) (join ...)) to produce the data structure that represents the query. Then you call (jdbc/execute! data-source (honeysql/format dsl-data))


That‘s true. It is actually that easy


Clojure's way is all about "simple", rather than "easy". ORMs can seem "easy" but they are definitely not "simple".

rich 4

So an ORM is basically something that is overengineered?


And where do you put your queries? Do you put them next to the API endpoints that need them? Or do you group them in namespaces like all user queries go into a user namespace?


I've used a bunch of ORMs over the decades, including Object Databases when those were a thing, and I do think they're over-engineered but they're also problematic in so many ways.


Heh, years ago, I even gave a conference talk about the problems with ORMs 🙂 Have you read Ted Seward's piece (from years ago) arguing that ORMs are the "Vietnam" of Software Engineering?


As for where to put the queries, it really depends on how big/complex your app is. There are lots of ways to structure code and Clojure isn't very opinionated about that. The only guiding principle is to try to keep side effects at the edges and write as much of your code as possible as simple, pure functions that are easy to test/reason about.


That's the one!


Is your talk also available online? I was not able to find it


Not online. It was at a conference that didn't video talks.


I haven't spoken at any conferences now for nearly seven years. I was a fairly regular speaker around the world before then for Macromedia/Adobe-related tech (where I worked 2000-2007).


I see. Well, thanks for your time and input. I’ve got a lot to read now ! For my next application I‘ll try out the Clojure way of working with the database 🙂


If you have any Qs about SQL/JDBC stuff there's a #sql channel and there's also a #honeysql channel if you go that way.