I just discovered this rather cute property of the type system:
_typeof(0);
(11) Result: zero
_typeof(_typeof(0));
(12) Result: type(zero)
_typeof(_typeof(_typeof(0)));
(13) Result: type(type(zero))
_typeof(_typeof(_typeof(_typeof(0))));
(14) Result: type(type(type(zero)))
_typeof(_typeof(_typeof(_typeof(_typeof(0)))));
(15) Result: type(type(type(type(zero))))
I wonder if this can be used to implement integer arithmetic by just using the type system? :-)
Unfortunately, typeof() doesn't seem to be as clever:
typeof(0);
(16) Result: zero
typeof(typeof(0));
(17) Result: type(mixed)
typeof(typeof(typeof(0)));
(18) Result: type(mixed)
typeof(typeof(typeof(typeof(0))));
(19) Result: type(mixed)
Even more interresting is:
typeof(_typeof(0));
(1) Result: type(zero)
typeof(_typeof(_typeof(0)));
(2) Result: type(type(zero))
typeof(_typeof(_typeof(_typeof(0))));
(3) Result: type(type(type(zero)))
typeof(_typeof(typeof(_typeof(0))));
(4) Result: type(type(mixed))
typeof(_typeof);
(5) Result: function((0=mixed) : type(0))
typeof(typeof);
Compiler Error: 1:typeof is a reserved word. Compiler Error: 1:parse error
/ Henrik Grubbström (Lysator)
Previous text:
pike-devel@lists.lysator.liu.se