Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Enum and Union
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AsianSensation




PostPosted: 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
Sponsor
sponsor
Dan




PostPosted: 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




PostPosted: Mon Jul 21, 2003 6:38 pm   Post subject: (No subject)

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




PostPosted: 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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: