Profile of Kean Santos

Personal Website

Posts

Clojure: implementing foldr

Clojure: foldr (fold right)

Immutability and State

Merge sort in Scala, part 2

Merge sort in Scala, part 1

Merge sort in Clojure, part 2

Trying out Clojure

25 November 2015

Immutability and State

by Kean Santos

Until recently, most of my exploration of Clojure has been with ‘large functions’ (as described on https://clojure.org/state). My largest program was a sudoku solver, and all it returned was a list of values representing solutions to the sudoku board.

I finally had to deal with state when writing my role-playing game at https://www.ersbane.com/ (still at a very early stage). In imperative programming, I would handle changes to creatures, rooms and items by directly updating values, and possibly wrapping those updates with locks. In clojure, I apply functions to do the updates. These functions are composable and are applied using a CAS operation, that ensure consistency over time. A much better explanation is at the Clojure for the Brave and True website: https://www.braveclojure.com/zombie-metaphysics/.

tags: