Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site telesoft.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!ittatc!dcdwest!sdcsvax!telesoft!bruceb From: bruceb@telesoft.UUCP (Bruce Bergman @favorite) Newsgroups: net.lang.mod2 Subject: functions returning structured types Message-ID: <331@telesoft.UUCP> Date: Thu, 12-Jun-86 11:59:00 EDT Article-I.D.: telesoft.331 Posted: Thu Jun 12 11:59:00 1986 Date-Received: Tue, 17-Jun-86 06:47:36 EDT Organization: TeleSoft, SanDiego CA Lines: 81 [Yes, Virginia, there REALLY is a line eater...] I have a question that I believe I know the answer to, however I want to verify it with someone who may know the history or reason why there appears to be confusion. In "Programming in Modula-2" by Wirth (3rd edition) [1], I am told that procedure functions may return any type that is UNSTRUCTURED. That is, anything like INTEGER, an enumeration, etc., while not allowing records, ARRAYs OF CHAR, etc. While this is okay with me (even though I'd like it otherwise), Richard Gleaves, in his book "Modula-2 for Pascal Programmers" [2] says that procedure functions can return ANY type. He doesn't bother to go into detail in any examples (all return simple types), so I can only assume that he means that the version of compiler that he was using can support functions that return any type. The alternative is that somebody is wrong, or there has been changes between the books. I note that Gleaves' book cites many examples that lead me to believe that he based his text on the Second Edition of Wirth's book. My compiler (FTL Modula-2) can return structured types as long as they are assigned to a variable rather than used in a procedure. Take for example: MODULE Test; FROM Terminal IMPORT WriteString, WriteLn; TYPE TimeType = ARRAY [0..14] OF CHAR; PROCEDURE ReturnTime() : TimeType; BEGIN (* fill in your favourite code *) END ReturnTime; VAR time : TimeType; BEGIN WriteString("The current time is: "); (* this next line won't work in FTL *) WriteString(ReturnTime()); (* but these two DO work *) time := ReturnTime; WriteString(time); WriteLn; END Test. In my opinion, Wirth should be the correct version, since he is very clear that procedure functions don't return structured types (in other words, not just a typo), while Gleaves' text appears that it MIGHT be a typo. My compiler really abides by Wirth, except that it allows the function declaration when it shouldn't (if it's not going to work properly at run time). Anyone have any clarifing comments? References: [1] "Programming in Modula-2", Third Corrected Edition, Niklaus Wirth. Pp. 55-56. [2] "Modula-2 for Pascal Programmers", Richard Gleaves, Pg. 62 and 73. Thanks Bruce -- bang!- allegra!\ \ crash! \ gould9!--\ ihnp4! \ \ >--sdcsvax!---->--telesoft!bruceb (Bruce Bergman N7HAW) noscvax! / / scgvaxd! / sdencore!--/ ucbvax! / / talaris!-