Task

Create an enumeration of constants with and without explicit values.




 
Module Checkit {
      \\ need revision 15, version 9.4
      Enum Fruit  {apple, banana, cherry}
      Enum Fruit2  {apple2=10, banana2=20, cherry2=30}
      Print apple, banana, cherry
      Print apple2, banana2, cherry2
      Print Len(apple)=0
      Print Len(banana)=1
      Print Len(cherry)=2
      Print Len(cherry2)=2, Cherry2=30, Type$(Cherry2)="Fruit2"
 
      k=each(Fruit) 
      While k {
            \\ name of variable, value, length from first (0, 1, 2)
            Print Eval$(k), Eval(k), k^
      }
      m=apple
      Print Eval$(m)="apple"
      Print Eval(m)=m
      m++
      Print Eval$(m)="banana"
      Try {
            \\ error, m is an object
            m=100
      }
      Try {
            \\ error not the same type
            m=apple2
      }
      Try {
            \\ read only can't change
            apple2++
      }
      m++
      Print Eval$(m)="cherry", m
      k=Each(Fruit2 end to start) 
      While k {
             Print Eval$(k), Eval(k) , k^   
             CheckByValue(Eval(k))
      }
      m2=apple2
      Print "-------------------------"
      CheckByValue(m2)
      CheckByReference(&m2)
      Print m2
 
      Sub CheckByValue(z as Fruit2)
            Print Eval$(z), z
      End Sub
 
      Sub CheckByReference(&z as Fruit2)
            z++
            Print Eval$(z), z
      End Sub
}
Checkit
 