CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for record-types
2003 |
In our seminar we were given the syntax to (a) create our own data type which is usefull for the coordinates and (b) fill the data type with values.
I can create my own data type with no trouble, but assigning a data type of:
DATA TYPE COORDS RECORDS INT x,y: :
the way we were shown:
[5] COORDS phil.pos[[*,*],[*,*],[*,*],[*,*],[*,*]]: (with the * as INT's)
doesn't work - I have tried messing about to get it to work but to no avail. Any obvious problems with this syntax?
The syntax is nearly there, but not quite. Constants in occam aren't like variables; they're constants, not variables that you can't assign/input to. Thus the declaration of these is slightly un-expected. As a minor point, `RECORDS' in your data-type definition should just be `RECORD'.
The correct way to declare a set of constant co-ordinates (using your record type) would be:
VAL []COORDS phil.pos IS [[*,*], [*,*], ...]:
You don't need to give the array-dimension explicitly here -- the compiler can count the number of things on the right-hand side.
If, however, you want to change these values as the program runs, you'd need a real variable array:
[5]COORDS phil.pos: SEQ phil.pos := [[*,*], [*,*], ...]
.. or the shorter way using an INITIAL declaration.
See also the answer to Question 68 (2000).
Keywords: record-types , table
2002 |
What is a RECORD used for?
This is not examinable. See:
\\raptor\files\courses\co516\etc\records.txt
if you want some information.
Keywords: record-types
Referrers: Question 44 (2002)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |