[r-t] delta based transposition for blue line generation

Mark Davies mark at snowtiger.net
Sat Jun 11 20:05:06 UTC 2016


I like the delta representation, Alan. It's a useful way of dealing with 
general permutations as well as standard and jump changes. I guess it 
would be nice to see it manifested as a Scala class rather than simply a 
Seq[Int] though. In my code I use a Perm class for this. The return 
signature of your expandPart method would then be more pleasant:

	def expandPart(pn: String): Seq[Perm] = ...

Also I wonder whether the bowels of your parsing code could be made 
simpler by adding -1 and "stage" to the sequence of place notation 
digits before generating the deltas. You might not need the special 
cases for head and last then. Something like:

	var p = -1 +: c.toSeq.map(CCBRToPlace) :+ stage
	p.sliding(2).flatMap(...)

Actually you might be able to get rid of the special case for "-" this 
way, too. You'd need to CCBRToPlace to return a sequence of results; 
normally one item, but nothing for "-", and use a flatMap to coelesce.

Of course to create the Perm instance, instead of Seq[Int], you'd need a 
suitable constructor / companion object apply():

	Perm( p.sliding(2).flatMap(...) )

Finally, I think I would also pull out helper methods for the string 
splits in the outer for loop, and also maybe the partial function 
(cases) creating the deltas. You'd end up with something simpler and 
maybe easier to read:

      def expandPart(pn: String): Seq[Perm] = {
        for (c <- splitPN(pn)) yield {
           var p = -1 +: c.toSeq.flatMap(CCBRToPlace) :+ stage
           Perm( p.sliding(2).flatMap(makeDelta) )
        }
      }

Other than that minor refactor (err... which probably needs debugging!) 
I like the code and the concept.

MBD


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus





More information about the ringing-theory mailing list