inconvergent

In the previous post i described a feature of my common lisp library. Namely the ability to easily create a graph of future alterations that depend on each other. This is achieved by naming the result of an alteration, and referencing named results inside the same context.

The Architect is Losing his Mind
The Architect is Losing his Mind

Being able to write algorithms like this is interesting to me because it feels expressive. And it hides a lot of the necessary book-keeping behind the scenes. It is also an interesting challenge from a programming perspective.

As you may have realized, the feature I have described so far does not deal with references to futures inside a loop. Fortunately this is also possible. But it has to be done in a slightly more involved manner.

Computer is Bored
Computer is Bored

Below is and example where the symbol g is created with (gensym). Which means that, g will be a distinct symbol in every iteration. Consequently, there is a distinct future available for every group created by (weir:add-grp! ...).

(weir:with (wer % :db t)
  ; 10 points in range 2 to 11
  (loop for x in (math:linspace 10 2d0 11d0)
        ; g gets a new value for each iteration
        do (let ((g (gensym "g"))
                 (xy (vec:vec x y))
                 (s (vec:vec 1d0 80d0)))
             ; the resulting alteration is named g
             (% (weir:add-grp? :name g) :res g)
             ; add-path? depends on g
             (% (weir:add-path? (list (vec:sub xy s)
                                      (vec:add xy s)) :g g)
                  :arg (g)))))

Note that there has to be a future (:res) for every for every reference (:arg), otherwise it will loop indefinitely while waiting for the non-existing future to resolve.

So far this seems to satisfy all the functionality I had in mind when when I started, but I haven't used it for very long yet, so we'll see. If this is interesting to you, there is some more details about this functionality in the Weir Github repo.