[net.lang.mod2] functions returning structured types

bruceb@telesoft.UUCP (Bruce Bergman @favorite) (06/12/86)

[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!-

kpk@gitpyr.UUCP (06/16/86)

In article <331@telesoft.UUCP>, bruceb@telesoft.UUCP (Bruce Bergman @favorite) writes:
> 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.
> 
Gleaves book is based on some chapters from the Volition Systems
Modula-2 reference manual.  (He wrote theses chapters while
working for Volition Systems.)  Thus his descriptions are biased
in favor of his company's compiler.