Hymn 0.5 released

If you read my earlier post about compound actions, you’ll probably remember that I’m using Hymn for monads. Just recently version 0.5 was released. The most interesting new feature for me are monad-> and monad->> threading macros. These work similarly to -> and ->> macros in standard library, but are supposed to be used with monads.

These allow writing the previous example in a shorter format:

(defn lunge [character direction]
  (do-monad [moved-1 (move character direction)
             moved-2 (move moved-1 direction)
             attacked (attack moved-2 direction)]

can be written as:

(defn lunge [character direction]
  (monad-> (move character direction)
           (move direction)
           (attack direction)))

Quite a nifty looking piece of code, isn’t it?

Compound actions

Recently I decided to add a lunge action in Herculeum, which would make the character first move and then attack. This could be used to cover short distances and launching surprise attacks. Naturally I wanted to avoid duplication of code and set to look into how to combine two actions and execute them as one. Like quite often in software world a serendipitous event happened and I learned that there exists monad library for Hy called hymn. With some work on the code, I could use either monad to chain actions together in a rather neat way.

Continue reading