@@ -1,11 +1,11 @@
1−---
2−navhome: /docs/
3−title: Scala
4−sort: 4
5−next: true
6−---
1+:- :~ navhome/'/docs/'
2+ next/'true'
3+ sort/'4'
4+ title/'Scala'
5+ ==
6+;>
77
8−# Scala
8+# Scala
99
1010From [Steve Randy Waldman](https://github.com/swaldman/nnnock/blob/master/src/main/scala/com/mchange/sc/v1/nnnock/package.scala):
1111
@@ -20,12 +20,13 @@ package object nnnock {
2020
2121 def nock( a : Noun ) : Noun = *(a)
2222
23+
2324 object Cell {
2425 private def apply( nl : List[Noun] ) : Cell = {
2526 nl match {
26− case a :: b :: Nil => Cell(a, b);
27− case a :: b :: c :: Nil => Cell(a, Cell(b, c));
28− case a :: b :: c :: tail => Cell(a, this.apply( b :: c :: tail ) );
27+ case a :: b :: Nil => Cell(a, b);
28+ case a :: b :: c :: Nil => Cell(a, Cell(b, c));
29+ case a :: b :: c :: tail => Cell(a, this.apply( b :: c :: tail ) );
2930 }
3031 }
3132 def apply(a : Noun, b : Noun, tail : Noun*) : Cell = apply( a :: b :: tail.toList );
@@ -59,28 +60,29 @@ package object nnnock {
5960 /(Cell(num, /(Cell(a, b))));
6061 }
6162 case a => /( a ); //intentional endless spin
62− }
63+ }
64+
6365
64− def *( noun : Noun ) : Noun = noun match {
65− case Cell( a, Cell(Cell(b, c), d) ) => Cell( *(Cell(a,b,c)), *(Cell(a,d)) );
66− case Cell( a, Cell(Atom(value), tail) ) => {
67− (value, tail) match {
68− case (0, b) => /( Cell(b, a) );
69− case (1, b) => b;
70− case (2, Cell(b, c)) => *( Cell( *( Cell(a,b) ), *( Cell(a,c) ) ) );
71− case (3, b) => ?( *( Cell(a,b) ) );
72− case (4, b) => plus( *( Cell(a,b) ) );
73− 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?
75− 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
77− 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) );
79− case (10, Cell(b, c)) => *( Cell(a,c) );
80− case _ => *( noun ); //intentional endless spin
66+ def *( noun : Noun ) : Noun = noun match {
67+ case Cell( a, Cell(Cell(b, c), d) ) => Cell( *(Cell(a,b,c)), *(Cell(a,d)) );
68+ case Cell( a, Cell(Atom(value), tail) ) => {
69+ (value, tail) match {
70+ case (0, b) => /( Cell(b, a) );
71+ case (1, b) => b;
72+ case (2, Cell(b, c)) => *( Cell( *( Cell(a,b) ), *( Cell(a,c) ) ) );
73+ case (3, b) => ?( *( Cell(a,b) ) );
74+ case (4, b) => plus( *( Cell(a,b) ) );
75+ case (5, b) => heq( *( Cell(a,b) ) );
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?
77+ case (7, Cell(b, c)) => *( Cell(a,2,b,1,c) );
78+ case (8, Cell(b, c)) => *( Cell(a,7,Cell(Cell(7,Cell(0,1),b),0,1),c) ); //wtf2
79+ case (9, Cell(b, c)) => *( Cell(a,7,c,2,Cell(0,1),0,b) );
80+ case (10, Cell(Cell(b,c),d)) => *( Cell(a,8,c,7,Cell(0,3),d) );
81+ case (10, Cell(b, c)) => *( Cell(a,c) );
82+ case _ => *( noun ); //intentional endless spin
83+ }
8184 }
85+ case a => *( a ); //intentional endless spin
8286 }
83− case a => *( a ); //intentional endless spin
8487 }
85−}
8688```