[r-t] Writing method display software

Alan Burlison alan.burlison at gmail.com
Sat Oct 31 18:53:09 UTC 2015

On 31/10/2015 07:45, Stephen Beckingham wrote:

> Mark Davies sent some messages to the list about Scala in July 2012.
> It might be worth having a look at
> http://bellringers.net/pipermail/ringing-theory_bellringers.net/2012-July/thread.html

I have absolutely no idea what a Helixoid is but it's an interesting
read - thanks. Scala is pretty mainstream nowadays, I use it quite a
bit in the 'day job' and the fit with ringing seemed immediately
obvious to me. There are also other features that are useful that Mark
only touched on. One is lazy evaluation - you can easily create
infinite series for example. The technique is that you have a function
that generates the next value, and in addition generates a new
function that returns the next value after that. The list of values
never exists until it is inspected, so it takes neither time nor space
to generate values that are never actually used. It's useful for
goal-directed searches because the values in the search space that you
prune off and never visit are never generated.

The grandpappy of Functional languages is Haskell but that's a pure FP
language and quite a leap for people coming from traditional
procedural languages, scala is a 'blended' language so it's more
approachable for people coming from languages such as C++ or Java and
you can ease yourself in gradually.

To get the most from FP languages you need to change from thinking in
a procedural way - 'Loop over this, for each of those, loop over that,
if this is true then do the other" - and start thinking in a more
declarative way where you are applying a series of transforms to
groups of things all at once. It's a bit of a head bender at first,
but it allows you to express complicated processing pipelines in a
very concise way.

A simple example is figuring out if a change has any jump changes in
it - assuming I've picked up what they are correctly, i.e. where a
bell moves by more than one place.  Rather than iterating over the
places in the change individually, a more functional way of doing this
is to convert each place in the change into a pair, so for example the
first change of plain hunt on 6 is transformed from (2,1,4,3,6,5) to
((2,1),(1,2),(4,3),(3,4),(6,5),(5,6)), then the two halves of each
pair are subtracted and the absolute value taken, then any values that
are more than 1 are filtered out to yield the list of changes that
move by more than one place.  In Scala that's:

positions.zipWithIndex.filter( p => math.abs(p._1 - (p._2 + 1)) > 1).map(_._2)

There's one issue I glossed over above - like most programming
languages, indexes in Scala are 0-based whereas bell numbering is
1-based so it's necessary to adjust by 1. I'm probably going to change
my code to map 1-based bell numbers on input into a 0-based system as
it makes processing easier, then convert back to 1-based bell numbers
for display. I'll also probably convert changes from a place to delta
based representation for the same sort of reason, e.g. the first
change of plain hunt would be represented as (+1,-1,+1,-1,+1,-1)
rather than (2,1,4,3,6,5). That should make processing easier - I
think :-)

Alan Burlison

More information about the ringing-theory mailing list