Overthunk

Rockets, Athens and the Return of the Vex

Jun 30, 2020


Contents

What I learned

Chapter 8 is unlike the previous chapters in CFGU in that it’s primarily about using the knowledge we’ve already gained and using them all to build a functioning program. The “Function Program” in this case is modeling a Rocket (The Atlas V) and it’s flights.

I’m about halfway through this chapter and so far its a lot of thinking about how to represent a rocket’s state (mass, fuel, rate of fuel consumption etc) and creating functions that compute various parts of a rocket’s physics like thrust, it’s position in different coordinate systems etc.

for eg:

(defn atlas-v
 []
  {:dry-mass  50050
   :fuel-mass 284450
   :time 0
   :isp 3050
   :max-fuel-rate (/ 284450 253)
   :max-thrust 4.152e6})

This reminds me of reading where we talked about how to represent global state that can be modified.

I will be reserving a longer explanation of this Chapter for when I complete it.

Athens

Like I mentioned earlier, after doing some work with chapter 8, I started thinking about Athens and how I could contribute to it. To this end, I spent some time reading the various issues that the Core Team is working on as well as trying to understand the vision for v1 of Athens and how the various issues and PRs currently being worked on relate to this vision.

After doing this, I was curious about using Athens myself, so I decided to get a local copy running on my laptop. This turned out to quite easy by following the steps outlined in CONTRIBUTING.md. The build process did take some time, since lein has to pull in quite a few dependencies and build them. But beyond the built time, the process itself was quite seamless.

Once I got the build setup, I tried navigating the UI and seeing the current state of Athens. One thing that I immediately noticed was that the Athena search bar froze when I tried to enter any text. I was able to replicate this behavior on non-chromium based browsers like Firefox and Safari. Chromium-based browsers like Chrome and Edge seem to be unaffected.

4Clojure

I also ended up spending more than a reasonable amount of time trying to solve one problem - No. 28. It seems like the trend of being vexed by 4Clojure problems is eternal and cyclical on a weekly basis. Perhaps I will never be rid of it.

However, after trying multiple slightly varying iterations of the same recursive approach, I had a flash of inspiration for a different way. With this inspiration, I was able to come up with a working solution in a few minutes.

The problem was to write a function that would flatten a sequence of arbitrary depth into a sequence of depth 1 (without using the built-in flatten function).

My solution depends on a mix of iteration and recursion -

(defn new-flatten [xs]
  (if (some coll? xs)
    (new-flatten (mapcat (fn [x] (if-not (coll? x) (vector x) x)) xs))
    xs))

If there is atleast one element in the current input which is a collection itself, make every other element into a vector of length 1 and concat all these vectors. This has the effect of flattening all elements at the current depth. Recursively applying this process N times will flatten a sequence with max subsequence depth of N.

Takeaway

I was pretty happy that I was able to come up with the solution but also disappointed in myself that it took that long to do so. The insight that I gained from working on this was that, if you’re spending too much time on a particular implementation without much progress, it helps to disengage from the problem for a while and try an implementation that is fundamentally different (or atleast think of a different approach).

Ultimately, today ending up being a productive day where I attempted to do many different things.

I’m trying to re-align my longer term goals to a bit more oriented towards practical knowledge that I can use to contribute effectively to the Athens codebase. But at the same time, I don’t want to miss any technical knowledge of Clojure that could potentially help.

I guess that’s a problem for tomorrow!