CompuServe Thread

#MODULA-2

5 messages in this thread
#46667From: Michael St. LaurentJan 1, 1987 7:52 PM
I can't figure out why this won't compile. Am I doing something wrong or is there a bug in the compiler? The books on MODULA-2 that I have read say that this should work. MODULE Test (* Test the open array as a parameter *) VAR testone : ARRAY [0..9] OF CHAR; PROCEDURE Assign (VAR testone: ARRAY OF CHAR); VAR testtwo : ARRAY [0..9] OF CHAR; BEGIN testone := testtwo; END Assign; BEGIN Assign(testone); END Test. I have also tried declaring a type and using it for both variables, but it still gave me a "Type incompatibility" error. Also, is there a way to declare this constant: ARRAY [0..12] OF ARRAY [0..9] OF CHAR; It works in Turbo Pascal… is there a way to fake it in MODULA?
#46691From: Steve FaiwiszewskiJan 1, 1987 10:52 PM
You cannot assign one variable to another if they are not of the same type (even if the declaration of both vars are the same: ARRAY[0..n] OF CHAR, they are considered to not be the same). To declare a two dimensional array do: ARRAY[0..12],[0..9] OF CHAR. Hope this helps, – Steve –
#46718From: Michael St. LaurentJan 2, 1987 12:46 AM
Thanks for the reply. I am still confused about my second question though. What I meant was that I wanted to do something like this: CONST DayNames : ARRAY [0..6] OF ARRAY [1..9] OF CHAR = ('Sunday', 'Monday', 'Tuesday' 'Wednesday', 'Thursday', 'Friday', 'Saturday'); Any ideas? Thanks, –Mike–
#46823From: Daryl AndersonJan 2, 1987 2:38 PM
Mike, I believe I saw something about your first issue a few months back which said that you could define a type TYPEA which is an ARRAY[0..9] then assign this type to each item and then you can do the assignment between each item since they are now the same type (TYPEA, or whatever). Pardon incompleteness since I only follow Modula threads but don't yet do much programming in it. -da-
#46877From: Jim VogelJan 2, 1987 8:13 PM
(*To: Michael St. Laurent 72017,235 Michael, though it really feels like cheating, this is how I would do the code you had a question on.*) MODULE Test; FROM Strings IMPORT Assign, String; TYPE DaysArray = ARRAY [0..7] OF String; VAR DayOfWeek : String; DayList : DaysArray; PROCEDURE IniArray(VAR days : DaysArray); VAR n : CARDINAL; BEGIN days[1] := ("SUNDAY"); days[2] := ("MONDAY"); days[3] := ("TUESDAY"); days[4] := ("WEDNESDAY"); days[5] := ("THURSDAY"); days[6] := ("FRIDAY"); days[7] := ("SATURDAY"); END IniArray; PROCEDURE AssignDay (VAR dayname : ARRAY OF CHAR;daynum : CARDINAL); BEGIN Assign(dayname,DayList[daynum]); END AssignDay; BEGIN (*MAIN*) IniArray(DayList); AssignDay(DayOfWeek,3) END Test. (*This code compiles, links, and runs(though it doesn't do much!).Its only 1768 K when compiled.Hope this is some help in what you are trying to do, though there are probably better way's, as I'm stoll learning Mod-2 also. Like all the other reply's, all I can tell you is you can't assign two different TYPE decleration's to each other. Though maybe someone out there with the commercial version can tell us how TDI did it, to make the Strings.Assign procedure?*) (*Jim Vogel*)