pyherc updated to Hy 0.12.1

Most of my freetime coding has been spent updgrading pyherc codebase to work with the latest Hy. While I was at it, I decided to update all the dependencies to the latest too. As expected, it was Hy that required most of the effort.

Luckily, my past self had been diligently writing tests here and there and they did save me at the end of the day. My process of updating was really simple: update Hy to latest release, try to run tests, fix first problem in the long list and repeat until no more errors popped up. Things like true being changed to True were easy to spot and fix. New defclass syntax took a bit more effort, but I’m really loving it! Because now, instead of writing

(defclass Cat [Animal]

  [[--init-- (fn [self name age]
               (setv name)
               (setv self.age age)

   [speak (fn [self]

I can write

(defclass Cat [Animal]
  [age None
   name None]

  (defn --init-- [self name age]
    (setv name)
    (setv self.age age))

  (defn speak [self]

It might not be a big change, but it makes prettier code and is more pleasant to work with. Let had similar change introduced in the recent Hy release and this was that kept me stumped for couple evenings. After everyting compiled, there was one function that kept failing. This function was meant to select coarse patterns within level and tag them. It’s very useful for building organic looking shapes, like veins of different types of rock and such. And for a very odd reason, I kept getting an error about trying to sum integer and tuple.


Two different types of stone

Turns out, I got bitten by the fact that setv returns tuple when multiple variables are assigned values. And let of course is implemented with setv. So the following code:

(defn coarsify-point [point data]
    (let [area↜ (area-around point)
          value-sum (sum (list-comp (get-value x data) [x area↜]))
          score (+ (get-value point data)
                   (* value-sum 0.025))]))

which used to return last assigned value now returned all assigned values as a tuple. Correctly written version shown below worked just fine:

(defn coarsify-point [point data]
    (let [area↜ (area-around point)
          value-sum (sum (list-comp (get-value x data) [x area↜]))
          score (+ (get-value point data)
                   (* value-sum 0.025))]

I’m just glad that I actually had a test case that caught that. Otherwise there would have been a bug (as if there weren’t enough of them already there) lurking inside the software for who knows how long.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s