David H. Friedman
Book Reviews Blog Performances Tags About
Recent Posts Recent Reviews

Implementing StarLogo

posted May 27 2021

Code

StarLogo is a parallel-processing simulation language designed by Mitchel Resnick in the ’80s, extending ideas from Logo.

Logo was designed to teach children logical and procedural thinking, particularly in terms of “turtle graphics”: moving a turtle about on a flat surface and drawing lines. Sophisticated geometry can be explored procedurally: Abelson and DiSessa’s Turtle Geometry treats vector graphics, topology, and general relativity.

Resnick designed StarLogo to help teach systems thinking, and used it successfully with groups of high-school students. He describes several of these projects and investigations in Turtles, Termites, and Traffic Jams.

StarLogo specifies simulations in terms of turtles - mobile agents - and patches - fixed pieces of ground. Turtles and patches can have properties which can be set and tested, and procedures that execute repeatedly and concurrently for each patch or turtle.

(StarLogo was first implemented on a Connection Machine, a massively parallel SIMD computer; by convention, parallelized versions of various programming languages were named with a “∗”, for example *Lisp and C*, hence the name StarLogo. Versions of StarLogo were implemented on Macintoshes and in Java.)

I thought it would be fun to implement a StarLogo and play with the simulations described in the book. As I am learning Go, so my first thought was to model StarLogo demons as goroutines. As I don’t know how to do GUIs in Go yet I decided to prototype in JavaScript.

Here’s an outline:


a_simulation.js

sketch = {
  setup: () => { ...initialization... }
  step: () => { ... }
}

starlogo.js

const canvas = ...
const ctx = ...

const turtle_demons = []
const patch_demons = []

function Turtle () { this.x = random(); this.y = random(); ... }
Turtle.prototype.forward = function (n) { ... }
Turtle.prototype.right = function (a) { ... }
Turtle.prototype.draw = function () { ... }
Turtle.prototype.activate_demon = function (demon) { turtle_demons.push(demon) }
...

function Patch (row, col) { this.id = [row, col]; this.center = ...; this.color = ...; }
Patch.prototype.get = function (property) { ... }
Patch.prototype.set = function (property) { ... }
Patch.prototype.draw = function () { ... }
Patch.prototype.activate_demon = function (demon) { patch_demons.push(demon) }
...

const turtles = []
const patches = []

const setup = () => {
  for (let i = 0; i < TURTLES; i++) { turtles.push(new Turtle()) }
  for (let i = 0; i < PATCHES; i++) { patches.push(new Patch()) }
  ...
  sketch.setup()
}

const step = () => {
  sketch.step()
  for(d of turtle_demons)
    for(t of turtles)
      d(t)
  for(d of patch_demons)
    for(p of patches)
      d(p)
}

setup()

The heart of the simulation is the step function in starlogo.js. It executes the sketch’s own step and then each of the demons for each of the turtles and patches. There are a current-state and a next-state as is usual in cellular automata implementations, which I left out of the sketch above.

Cosma Shalizi wrote a fine essay at The Bactra Review on the paedagogy and the politics of decentralized systems in Prof. Resnick’s book.

“The heart of the book, on how to teach people about decentralized processes and emergent behaviors, and the tricky process of designing and controlling them, is excellent. Since I happen to think that self-organization is both quite important and quite neat, this is to me a thing of joy; and no doubt people with different scientific and philosophical biases will find Resnick’s woollier ideas congenial.” – Cosma Shalizi

Practice & Habits

posted May 15 2021

My guru Charles Cooke, staff writer on The New Yorker and avid amateur pianist, whose Playing the Piano for Pleasure 1 got me started and has been a great practical influence, wrote:

When you substitute a good habit for a bad one, or when you decide to acquire a habit where none existed before, the new habit must function at first, for a little while, from power supplied by you. This is the stage where we have to make a strong conscious effort, even to the extent of a sensation of spiritual pain. But in a surprisingly short time the habit begins to take over the task of supplying power; it begins to develop its own momentum; and finally we get a sensation of spiritual pain if we don’t exercise the habit.

I’m starting to feel “spiritual pain" when I don’t play the piano: I miss playing, I feel a mild longing to play, when too much of a day has gone by before I start.

The reluctance to sit down and play came, I think, from beginner’s frustration. Every mistake led to self-judgement. Who wants to play under constant criticism? I think I’m starting to break the habit of self-judgement.


  1. Cooke, Charles. Playing the Piano for Pleasure: The Classic Guide to Improving Skills Through Practice and Discipline. Skyhorse Publishing (2011) ISBN: 978-1-61608-230-7 Originally published by Simon and Schuster, 1941. ↩︎

On Slow Practice

posted May 7 2021

Quotations from Charles Cooke’s On Playing Piano 1

Josef Hofmann once said in conversation: “Few people realize what can be done by playing a difficult piece six times a day, very slowly, for three weeks; then putting it aside for a few days, and repeating the process.”

Let me recommend very slow playing, with the most minute attention to detail" (Teresa Carreño).

The worst possible thing is to start practicing too fast: it invariably leads to bad results and lengthy delays." (Ernest Schelling).

Slow practice should be used as assiduously for practicing pieces as for setting fractures. You will be amazed, I think, at the rapidity of your progress if you bear this in mind.

Josef Hofmann once said in conversation: “Few people realize what can be done by playing a difficult piece six times a day, very slowly, for three weeks; then putting it aside for a few days, and repeating the process.”

You may have been wondering what you should do when, at this point in your work, you play a passage incorrectly. The answer is: don’t merely correct the wrong notes and then go on. Go back and choose a dowel pin at the beginning and another at the end of the passage that went wrong; then practice the passage, with its dowel pins, until it runs accurately and smoothly. Otherwise, you will certainly stumble again at the place the next time you come to it.

I’m going to make the confident assumption that no such flaw can occur at a place which was originally a fracture; for all the original fractures are of course set and are therefore stronger than any other places in the piece. Consequently, flaws can come only at places which are technically not forbidding. Nevertheless, set them like full-fledged fractures, with all the expertness you have acquired, and fit them snugly into their context. Halting to correct merely the wrong notes themselves will form lamentably wrong associations; it’s what Matthay calls, with sublime aptness, Unpractice or Dispractice.


  1. Cooke, Charles. Playing the Piano for Pleasure: The Classic Guide to Improving Skills Through Practice and Discipline. Skyhorse Publishing (2011) ISBN: 978-1-61608-230-7 Originally published by Simon and Schuster, 1941. ↩︎

Dead Lies Dreaming

reviewed May 6, 2021

Series was brilliant, Len Deighton meets Lovecraft and I’ve no end of good things to say about the first six or seven but it has drifted from its remit and I’m reading out of mere inertia tinged with hope.

A Long Spoon (Johannes Cabal, #4.5)

reviewed March 27, 2021

I’m in love with Zarenyia. I’m delighted with Cabal’s disconcert at being liked. I love a savage grin that once sent a Hellhound running, yelping for its mother. I loved the clever way the big bad was defeated.

Fantasy Magazine, April 2011

reviewed March 9, 2021

This is a review only of Jonathan L. Howard’s Johannes Cabal story The House of Gears.

(I also read Kat Howard’s Choose Your Own Adventure, which was beautiful and chilling and marvelous.)

(Other authors in this issue are Peter S. Beagle, Carrie Vaughn, John Joseph Adams, N. K. Jemisin, and Genevieve Valentine.)

spoilers

Necromancer vs. Steampunk AI. The description of the mechanical brain is marvelous, clanky, clunky yet eerily Kubrick. There is Howard’s trademark dry humour: Cabal hiding behind an Aspidistra in a Chinese pot waiting for the antagonist to change his mind when an improvised flash bomb wipes out one day’s long-term memory; Samhet’s apotheosis conveyed in a shot of his brain in formaldehyde, pickled in a jar of pickled onions. There is also horror of the proper old sort: the brief mention of of dried blood and bone dust clogging a drill, indicating Samhet’s sheer determination to endure the pain of days or weeks of decanting. What Lovecraft needed two pages of piled up adverbs and adjectives to convey, Howard achieves in two sentences.

The choice of the image of Möbius loops for the memory devices. The hideous aesthetics of the poor little mad genius. The dull horror of the pithed, mechanized necromancers. Cabal’s efficient vengeance in the form of reprogramming Samhet for Cabal’s own future use. The only difference between them, then, that Samhet is actively malevolent; Cabal only reactively so.

Howard’s stories alternate between supernatural and steampunk. The steampunk is excellent, but the supernatural is better: Cabal’s personality is deeper, more nuanced, and more interesting in the horror stories; he is slightly more sketchy or perhaps stereotyped or perhaps, dare I say, mechanical, in the steampunk stories.

A Computer Scientist's Guide to Cell Biology

reviewed February 27, 2021

As promised in the prologue, the book reads like a student’s class notes for an introductory course.

Professor Cohen is an expert in Machine Learning who took an interest in the applicability of his subject to bioinformatics and wrote this short book as a summary of his preliminary reading. It is not accessible to someone lacking a good high-school background in biology and organic chemistry; neither will it adequately refresh the details for one for whom the subjects have lain dormant for long. It will, however, prime the mind beautifully for the rest of the journey which it is presumed one to whom this book appeals intends to undertake.

The first section sketches DNA transcription and replication; the long middle section is a very detailed overview of some modern experimental techniques and the final brief section touches on the applications of computer science to bioinformatics.

I was struck particularly by Prof. Cohen’s metaphor for experimental biology: we are rather like giants smashing up great collections of minute and complicated machines and coarsely examining the aggregate detritus for a rough sense of the composition of the machines. (His metaphor is delightful extended: imagine a pile of personal computers laid out on a shag carpet, crushed by steamrollers, blown by the fan of a jet engine; the lighter parts blow further before the carpet snags them. We are left with bands of material graded from heavier to lighter and might conclude that a computer is composed of two or three sorts of metal and plastic organized in concentric shells.)

An illuminating section on reaction rates discusses molecular motion, the relative viscosities of cellular membrane and plasma (as butter to water), distances covered by diffusion (under random walk motion the time to cover a certain distance is as the square of the velocity, not linear with velocity) and contact probabilities, which may explain why diffusion is adequate in bacteria but that in larger cells reactions often take place along two dimensional membrane surfaces, where constrained motion increases the chances for reaction.

Other highlights: the behaviour of ion channels in nerve cells is nicely explained, protein gated channels a little less so (they are more complicated), discussion of energy transfer is too large a topic; the notes are merely a starting point.

In short; exactly as advertised, an excellent re-orientation and a guide to what to study next.

  • ««
  • «
  • 1
  • 2
  • 3
  • 4
  • 5
  • »
  • »»

Recent Book Reviews

September 2, 2026
Creation of The Humanoids (film, 1962)
November 18, 2025
Can You Forgive Her?
May 15, 2025
Augustus
May 21, 2025
Gods of the Ancient Northmen
August 31, 2021
Et in sempiternum pereant
August 31, 2021
The Quy Effect
May 6, 2021
Dead Lies Dreaming
March 27, 2021
A Long Spoon (Johannes Cabal, #4.5)
March 9, 2021
Fantasy Magazine, April 2011
February 27, 2021
A Computer Scientist's Guide to Cell Biology

Recent Posts

May 31 2021
Implementing StarLogo: diffusion
May 27 2021
Implementing StarLogo
May 15 2021
Practice & Habits
May 7 2021
On Slow Practice
Jan 8 2021
Latin and ATNs
Sep 12 2020
Caffeine
Jun 22 2020
Irving Finkel, Assistant Keeper of Mesopotamian script, languages, and cultures
Feb 13 2020
Brennan B2
Dec 10 2019
Clock Module
Dec 3 2019
Wire stripper
Copyright 2026 David H. Friedman.