----------------------------------- AsianSensation Sun Jul 20, 2003 9:09 pm Enum and Union ----------------------------------- I'm having trouble understanding enum and union syntax, what do they do, and how do I use them efficently? ----------------------------------- Dan Mon Jul 21, 2003 5:26 pm ----------------------------------- well the enum things is a litte odd in turing. here is an expale i made to output colors: type colors : enum (red, green, blue, black, white, lightGreen, lightBlue, lightRed) var c : colors := colors.red put c for i : 1 .. 7 c := succ (c) put c end for honstety i dont realy see the point of them, in most progames this whould be realy needed. (can do same thing esaer with an array of strings). As for union: turing doc's say this about them: A union type (also called a variant record) is like a record in which there is a run time choice among sets of accessible fields. This choice is made by the tag statement, which deletes the current set of fields and activates a new set. basicly they have to do with recoreds, i dont know much about them since i have never used them in turing. ----------------------------------- AsianSensation Mon Jul 21, 2003 6:38 pm ----------------------------------- I just wanted to check on this union thing, because I was reading a tutorial somewhere, here, http://www.doc.ic.ac.uk/lab/firstyear/turing_lecture_notes/turing_lecture_9.html to be exact, and it says that union could be used to simulate polymorphism. Except the example was to confusing, hopefully someone will explain it to me. ----------------------------------- Catalyst Mon Jul 21, 2003 8:00 pm ----------------------------------- u dont have to simulate polymorphism in turing it can be implemented using the deferred key word ----------------------------------- rizzix Tue Jul 22, 2003 1:09 am ----------------------------------- well technincally the union is not used too often in the mordern world. it was used in the past, since at that time memory was an issue. a union lets u declare different variables to use a common memory area. well at least thats what a union means in c