@@ -1,11 +1,11 @@
2−navhome: /docs/
1+:- :~ navhome/'/docs/'
3−title: Scala
4+ title/'Scala'
10From [Steve Randy Waldman](https://github.com/swaldman/nnnock/blob/master/src/main/scala/com/mchange/sc/v1/nnnock/package.scala):
10From [Steve Randy Waldman](https://github.com/swaldman/nnnock/blob/master/src/main/scala/com/mchange/sc/v1/nnnock/package.scala):
@@ -20,12 +20,13 @@ package object nnnock {
21 def nock( a : Noun ) : Noun = *(a)
21 def nock( a : Noun ) : Noun = *(a)
23 object Cell {
24 object Cell {
24 private def apply( nl : List[Noun] ) : Cell = {
25 private def apply( nl : List[Noun] ) : Cell = {
25 nl match {
26 nl match {
26− case a :: b :: Nil => Cell(a, b);
27+ case a :: b :: Nil => Cell(a, b);
27− case a :: b :: c :: Nil => Cell(a, Cell(b, c));
28+ case a :: b :: c :: Nil => Cell(a, Cell(b, c));
28− case a :: b :: c :: tail => Cell(a, this.apply( b :: c :: tail ) );
29+ case a :: b :: c :: tail => Cell(a, this.apply( b :: c :: tail ) );
31 def apply(a : Noun, b : Noun, tail : Noun*) : Cell = apply( a :: b :: tail.toList );
32 def apply(a : Noun, b : Noun, tail : Noun*) : Cell = apply( a :: b :: tail.toList );
@@ -59,28 +60,29 @@ package object nnnock {
59 /(Cell(num, /(Cell(a, b))));
60 /(Cell(num, /(Cell(a, b))));
61 case a => /( a ); //intentional endless spin
62 case a => /( a ); //intentional endless spin
64− def *( noun : Noun ) : Noun = noun match {
66+ def *( noun : Noun ) : Noun = noun match {
65− case Cell( a, Cell(Cell(b, c), d) ) => Cell( *(Cell(a,b,c)), *(Cell(a,d)) );
67+ case Cell( a, Cell(Cell(b, c), d) ) => Cell( *(Cell(a,b,c)), *(Cell(a,d)) );
66− case Cell( a, Cell(Atom(value), tail) ) => {
68+ case Cell( a, Cell(Atom(value), tail) ) => {
67− (value, tail) match {
69+ (value, tail) match {
68− case (0, b) => /( Cell(b, a) );
70+ case (0, b) => /( Cell(b, a) );
69− case (1, b) => b;
71+ case (1, b) => b;
70− case (2, Cell(b, c)) => *( Cell( *( Cell(a,b) ), *( Cell(a,c) ) ) );
72+ case (2, Cell(b, c)) => *( Cell( *( Cell(a,b) ), *( Cell(a,c) ) ) );
71− case (3, b) => ?( *( Cell(a,b) ) );
73+ case (3, b) => ?( *( Cell(a,b) ) );
72− case (4, b) => plus( *( Cell(a,b) ) );
74+ case (4, b) => plus( *( Cell(a,b) ) );
73− case (5, b) => heq( *( Cell(a,b) ) );
75+ case (5, b) => heq( *( Cell(a,b) ) );
74− case (6, Cell(b, Cell(c, d))) => *( Cell(a,2,Cell(0,1),2,Cell(1,c,d),Cell(1,0),2,Cell(1,2,3),Cell(1,0),4,4,b) ); //wtf?
76+ case (6, Cell(b, Cell(c, d))) => *( Cell(a,2,Cell(0,1),2,Cell(1,c,d),Cell(1,0),2,Cell(1,2,3),Cell(1,0),4,4,b) ); //wtf?
75− case (7, Cell(b, c)) => *( Cell(a,2,b,1,c) );
77+ case (7, Cell(b, c)) => *( Cell(a,2,b,1,c) );
76− case (8, Cell(b, c)) => *( Cell(a,7,Cell(Cell(7,Cell(0,1),b),0,1),c) ); //wtf2
78+ case (8, Cell(b, c)) => *( Cell(a,7,Cell(Cell(7,Cell(0,1),b),0,1),c) ); //wtf2
77− case (9, Cell(b, c)) => *( Cell(a,7,c,2,Cell(0,1),0,b) );
79+ case (9, Cell(b, c)) => *( Cell(a,7,c,2,Cell(0,1),0,b) );
78− case (10, Cell(Cell(b,c),d)) => *( Cell(a,8,c,7,Cell(0,3),d) );
80+ case (10, Cell(Cell(b,c),d)) => *( Cell(a,8,c,7,Cell(0,3),d) );
79− case (10, Cell(b, c)) => *( Cell(a,c) );
81+ case (10, Cell(b, c)) => *( Cell(a,c) );
80− case _ => *( noun ); //intentional endless spin
82+ case _ => *( noun ); //intentional endless spin
85+ case a => *( a ); //intentional endless spin
83− case a => *( a ); //intentional endless spin