Fork me on GitHub
#beginners
<
2019-10-06
>
skykanin00:10:02

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

hendore01:10:33

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?

SoV401:10:30

@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.

hendore01:10:16

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?

seancorfield03:10:49

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

seancorfield03:10:16

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

hendore04:10:42

@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.

hendore04:10:06

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

hendore04:10:40

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?

hendore04:10:38

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 😞

seancorfield06:10:37

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

hendore12:10:19

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

tomd12:10:31

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} "")

tomd13:10:36

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

hendore14:10:51

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.

SoV415:10:41

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

hendore15:10:12

Found verily (https://github.com/jkk/verily) for validating forms but also spec (https://clojure.org/guides/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?

seancorfield16:10:05

Spec is what we use at work. It's great for a lot of stuff https://corfield.org/blog/2019/09/13/using-spec/

hendore18:10:15

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

kenj19:10:04

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?

kenj19:10:32

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

andy.fingerhut19:10:17

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?

kenj20:10:02

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

andy.fingerhut19:10:54

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.

Nate Sutton20:10:39

flattening things a bit can help, and using meander for navigating deeply nested structures can make it easier to see the changes that need to be made when there are updates

chris_johnson20:10:34

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: https://github.com/Day8/re-frame

kenj05:10:19

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.