# A Lazy K

Work in progress here.

Meanwhile,

length l is if ~#l then 0 else 1+length 1 _ l;
length 1 2 3
3

fac n is if n=0 then 1 else n*fac n-1
fac 5
120

The execution-tree:

fac
({@}
`Y
({@}
({@}
({@}
`B_
({@}
`S
({@}
({@}
({@};`C_;{?})
({@}
({@}
`C
({@};{:};=))
0))
1)))
({@}
`S
({@};{:};*)))
({@}
({@};`C;`B)
({@}
({@}
`C
({@};{:};-))
1))))

i.e.,

disp fac
+---------------¯---------------+
¦                               ¦
`Y                   +-----------¯-----------+
¦                       ¦
+-----------¯------------+      +---¯----+
¦                        ¦      ¦        ¦
+----¯-----+                +-¯-+   +¯+     +-¯--+
¦          ¦                ¦   ¦   ¦ ¦     ¦    ¦
`B_  +------¯-------+       `S  +¯+ `C `B  +-¯-+  1
¦              ¦           ¦ ¦        ¦   ¦
`S         +----¯-----+    :: *       `C  +¯+
¦          ¦                   ¦ ¦
+----¯-----+    1                  :: -
¦          ¦
+-¯-+      +-¯--+
¦   ¦      ¦    ¦
`C_ cond  +-¯-+  0
¦   ¦
`C  +¯+
¦ ¦
:: =

The execution-trace:

[] `Y(`B_(`S(`C_ cond(`C(=)0)1))(`S(*))(`C
[] `C(=)0 5
[] 5
5 []
[] 0
0 []
0 []
[] 5
5 []
[] `C `B(`C(-)1)(`Y(`B_(`S(`C_ cond(`C(=)0
[] `C(=)0(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 0
0 []
0 []
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] `C `B(`C(-)1)(`Y(`B_(`S(`C_ cond(`C(=)0
[] `C(=)0(`C(-)1(`C(-)1 5))
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] 0
0 []
0 []
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] `C `B(`C(-)1)(`Y(`B_(`S(`C_ cond(`C(=)0
[] `C(=)0(`C(-)1(`C(-)1(`C(-)1 5)))
[] `C(-)1(`C(-)1(`C(-)1 5))
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] 1
1 []
2 []
[] 0
0 []
0 []
[] `C(-)1(`C(-)1(`C(-)1 5))
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] 1
1 []
2 []
[] `C `B(`C(-)1)(`Y(`B_(`S(`C_ cond(`C(=)0
[] `C(=)0(`C(-)1(`C(-)1(`C(-)1(`C(-)1 5)))
[] `C(-)1(`C(-)1(`C(-)1(`C(-)1 5)))
[] `C(-)1(`C(-)1(`C(-)1 5))
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] 1
1 []
2 []
[] 1
1 []
1 []
[] 0
0 []
0 []
[] `C(-)1(`C(-)1(`C(-)1(`C(-)1 5)))
[] `C(-)1(`C(-)1(`C(-)1 5))
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] 1
1 []
2 []
[] 1
1 []
1 []
[] `C `B(`C(-)1)(`Y(`B_(`S(`C_ cond(`C(=)0
[] `C(=)0(`C(-)1(`C(-)1(`C(-)1(`C(-)1(`C(-
[] `C(-)1(`C(-)1(`C(-)1(`C(-)1(`C(-)1 5)))
[] `C(-)1(`C(-)1(`C(-)1(`C(-)1 5)))
[] `C(-)1(`C(-)1(`C(-)1 5))
[] `C(-)1(`C(-)1 5)
[] `C(-)1 5
[] 5
5 []
[] 1
1 []
4 []
[] 1
1 []
3 []
[] 1
1 []
2 []
[] 1
1 []
1 []
[] 1
1 []
0 []
[] 0
0 []
1 []
1 []
1 []
2 []
6 []
24 []
120 []
120