Enum and Union
Author |
Message |
AsianSensation
|
Posted: Sun Jul 20, 2003 9:09 pm Post subject: Enum and Union |
|
|
I'm having trouble understanding enum and union syntax, what do they do, and how do I use them efficently? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Mon Jul 21, 2003 5:26 pm Post subject: (No subject) |
|
|
well the enum things is a litte odd in turing.
here is an expale i made to output colors:
code: |
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. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
AsianSensation
|
|
|
|
|
Catalyst
|
Posted: Mon Jul 21, 2003 8:00 pm Post subject: (No subject) |
|
|
u dont have to simulate polymorphism in turing
it can be implemented using the deferred key word |
|
|
|
|
|
rizzix
|
Posted: Tue Jul 22, 2003 1:09 am Post subject: (No subject) |
|
|
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 |
|
|
|
|
|
|
|