Fork me on GitHub

I wrote a function which converts an infix expression to a postfix one using the shunting-yard algorithm. I was wondering if there is a better way to write this function


Hi all, I’m just about getting started writing a web app, I’ve chosen ring and compojure for http server and routing, I’ll probably end up using jdbc for working with the database instead of an ORM library now I’m left with deciding on a html templating library, is there a standard/mostly recommended lib for server side rendered html?


@matt.henley rum is great. it is a wrapper over hiccup. rum can also make clojurescript/js files for single-page-apps. i would recommend looking at hiccup and using either straight hiccup or rum.


Thanks @sova I’ve used hiccup a little with reagent however I never thought about using it for server side templates. I was thinking more along the lines of traditional templating such as twig, pug, blade templates seen in other languages. Is hiccup used a lot for server side templates too?


@matt.henley We use Selmer very heavily at work. It's like Django in terms of templating.


That means you can use traditional HTML editing tools -- and work with designers etc if you need to.


@seancorfield Ah that looks exactly like what I was expecting, this will certainly come in handy when working with designers like you said, thanks for sharing.


I’ve dropped hiccup in tonight and I think it will be more than suitable for this small project 🙂


One more question (I hope). I’m using emacs/cider, normally I can start a repl and connect to it from emacs cider-jack-in then I can evaluate any form, I’ve gotten pretty comfortable with that. The problem I have now is with this being my first web app, when I evaluate the form that starts my server everything starts up and I can make requests to the server however I can no longer interact with the repl while the server is running, anyone have any ideas?


Trying to C-c C-e on (+ 1 2) but nothing happens when the servers running so it’s currently forcing me to kill the repl to reload changes 😞


@matt.henley most HTTP servers can be started in background -- the exact options differ between Jetty, http-kit, etc


Thanks again, I found a list of jetty options shortly after posting this question and tried setting join? to false which worked :thumbsup:


I'm trying to use clojure.edn/read-string and supply an :eof opt. It's not working and I can't see why. The documentation is sparse, and I can't find any examples online. This code throws an exception, but I'd expect it not to:

(clojure.edn/read-string {:eof :somevalue} "{:a 1")
(note the missing closing brace). Am I missing the point of the :eof opt, or should this, in fact, work?

Jan K13:10:07

@tomd The :eof option doesn't prevent exceptions for invalid EDN, it marks the end of a valid stream, ie. you get :somevalue for (clojure.edn/read-string {:eof :somevalue} "")


@jkr.sw I see, thanks. So try catch is the best option for handling invalid edn?

Jan K13:10:03


👍 4

Next up on my clojure web app adventure is validation, any recommendations? Not sure if this should be handled as ring middleware or elsewhere but open to options.


Hmmm Selmer is cool, reminds me of PHP and inline things like that


Found verily ( for validating forms but also spec ( looks like it could be used too, not sure which one to pick. One hand verily looks like the easiest to learn but spec seems like it might be a standard?


Spec is what we use at work. It's great for a lot of stuff


That was an interesting read, I had no idea spec was so much more than just validation.


I started to write a MUD as a learning project in Clojure. I ended up putting all the game state inside of a single atom, and now the code is full of get-in, update-in, assoc-in etc. along with key paths filled will the same keywords. This feels brittle somehow in that if I change my underly maps, a whole lot of code could need updating. Is this standard practice or is there a better way I’m missing?


I also realize this would be an issue in most other languages with nested objects/maps


Perhaps you are already doing this, but to some extent the issue could be reduced if sub-functions that only need to access or update small parts of the game state could be passed only the sub-part of the data they need, and not the entire game state?


Both of those are good ideas. I think I was avoiding the later one as it felt kinda like writing Java getters, but in this case would make more sense in that it’s wrapping more then just a single member var access


Another thought would be to give descriptive names to some functions that do nothing but get-in for accessing signficant parts of the game state, and use those names wherever applicable.


Even though your MUD is (probably?) not a ClojureScript SPA, I think that reading the re-frame docs might help you to clarify your thinking about, essentially, event sourcing and keeping state in one top-level atom:


Thanks! I’ve taken a lot of inspiration from re-frame after reading it’s thought provoking readme awhile back. I love the ideas of modeling side-effects as data.