Index: doc/theses/jiada_liang_MMath/user_define_enum.cfa
===================================================================
--- doc/theses/jiada_liang_MMath/user_define_enum.cfa	(revision efd055c61ef4a5bb3389700877cb9d285cb2285e)
+++ doc/theses/jiada_liang_MMath/user_define_enum.cfa	(revision efd055c61ef4a5bb3389700877cb9d285cb2285e)
@@ -0,0 +1,46 @@
+#include <fstream.hfa>
+#include <enum.hfa>
+#include <string.hfa>
+
+
+forall( E, V | TypedEnum( E, V ) | { string str( V ); } )       // routine to format value}$
+string format_enum( E e ) {
+       return label( e ) + '(' + str( value( e ) ) + ')'; // "label( value )"
+}
+enum(size_t) RGB { Red = 0xFF0000, Green = 0x00FF00, Blue = 0x0000FF };
+// string library has conversion from size_t to string
+
+
+struct color_code { int R, G, B; };
+enum(color_code) Rainbow {
+       Red = {255, 0, 0}, Orange = {255, 127, 0}, Yellow = {255, 255, 0}, Green = {0, 255, 0}, // ...
+};
+string str( color_code cc ) with( cc ) {
+       return str( R ) + ',' + str( G ) + ',' + str( B ); // "R,G,B"
+}
+
+
+enum Fruit { Apple, Banana, Cherry };                                   // C enum
+const char * label( Fruit f ) {
+       static const char * label[] =  { "Apple, ""Banana", "Cherry" };
+       return label[f];
+}
+
+
+int posn( Fruit f ) { return f; }
+int value( Fruit f ) {
+       static const int position[] =  { 0, 1, 2 };
+       return position[f];
+}
+
+
+string str( int f ) {
+       return f;
+}
+
+
+int main() {
+       sout | format_enum( RGB.Green );                // "Green(65280)"}$
+       sout | format_enum( Rainbow.Green );    // "Green(0,255,0)"}$
+       sout | format_enum( Cherry );                   // "Cherry(c)"
+}
