sfk@otter.hpl.hp.com (Steve Knight) (04/22/91)
Some while ago I posted the FAQ "Err ... what's modula-3". As promised, here is a only slightly edited summary of the replies I received. Thanks to everyone who took the time to help me out! Also, I was successful in recovering the postscript report from gatekeeper.dec.com, although I had to use the split version for stupid printers. Steve Knight, HP Labs, Bristol, UK replies follow: ----------------------------------------------------------------------------- From: MADMATS@ELCGL.EPFL.CH (Mats Weber) I think a previous article in this newsgroup gives bibliographic references on Modula-3. If you can't find them, you can get the modula-3 lang. report through anonymous ftp on gatekeeper.dec.com (it is named Report.ps and resides in /pub/DEC/Modula-3/<something>). An article describing Modula-3 appeared in Byte a few months ago, too. I think Modula-3 is very interesting. Basically, it's Modula-2 + objects with inheritance and dynamic binding + exceptions + better interface/module structure + Threads + garbage collection. Mats Weber ----------------------------------------------------------------------------- From: harbison@bert.pinecreek.com See my article in the November '90 BYTE for an overview of the Modula-3 language. There's also a second article in the upcoming (March) issue of Computer Language. The reference manual (60 pp.) is available as a tech report (#52) from Digital Systems Research Center, 130 Lytton Ave, Palo Alto CA 94301. There have been no direct comparisons with Modula-2, but Modula-3 is both more and less--it adds exceptions, threads, objects, garbage collection, and (more recently) generics. It takes away nested modules and simplifies the type system. It has a particlarly good system for defining opaque object types and hiding representations. It breaks virtually no new ground, but includes features of proven utility in various languages. In spite of all this, it still feels like a small language. M3 is not an extension of M2: M3 compilers won't compile M2 programs or vice versa, although a myopic M2 programmer might mistake an M3 program for M2. Other miscellania: M3 has initializations on variable declarations and default initialization of record and object types. The WITH statement is more like Lisp's LET than Pascal/Modula-2's WITH. The FOR statement automatically declares its control variable, like Ada. M3 is "safe" from undefined runtime behavior unless the programmer labels some interfaces or modules as UNSAFE, in which case he/she gets access to a few dangerous but occasionally useful functions such as DISPOSE, address arithmetic, etc. Summary: Modula-3 is a safe and robust programming language with the set of features needed by modern system programmers. Nevertheless, it still has the feel of a "small" language, in the spirit of Modula-2 and contrary to languages like Ada and C++. Sam Harbison Pine Creek Software, Pittsburgh, PA. +1 412 681 9811 ----------------------------------------------------------------------------- From: buschman@tubsibr.UUCP (Andreas Buschmann) Hi! I have a list of differences between modula-2 and modula-3, but it has some shortcommings: a. it isn't complete. i have done it last summer, and since then discovered some more things which i didn't add to the list. b. its my personal point of view. c. its in german. if you still want it, drop me a note, and, if you have, give me the id of your bitnet account. (its about 23kbyte of text) Tschuess Andreas /|) Andreas Buschmann /-|) TU Braunschweig, Germany (West) ^^^^ was ----------------------------------------------------------------------------- From: larry@titan.tsd.arlut.utexas.edu (Larry Maturo) You can ftp to gatekeeper.dec.com using anonymous ftp and then cd to pub/DEC/Modula-3 and download the Modula-3 source code and all it's associated documentation. Basically, Modula-3 is Modula-2 with objects. The objects are based on records, like C++, Turbo Pascal, and Quick Pascal. It also uses structural compatibility so that you can assign one array slice to another if the elements are of the same type, even though the arrays themselves are of different types. It does allow branding of types so that a variable of a branded type is only compatible with other variables of that branded type. It also has the concept of traced and untraced storage. Traced storage uses garbage collection and untraced storage dosen't. It also allows mixing and matching of interface modules and implementation modules instead of requiring that each implementation module have only one definition module. Hopes this helps. Larry Maturo | Opinions expressed herein must be Applied Research Laboratories | yours, neither I nor my employer have University of Texas at Austin | any. P.O. Box 8029 | Austin, Texas 78713-8029 | | When you're as great as I am it's hard larry @titan.tsd.arlut.utexas.edu | to be modest, but I succeed where | others fail. ----------------------------------------------------------------------------- From: Robert Stroud <R.J.Stroud@newcastle.ac.uk> Modula-3 = Modula-2+ + objects (single inheritance only) Modula-2+ = Modula-2 + exception handling + threads + "safe programming" For a good description of the rationale for Modula-2+, see the paper by Paul Rovner "Extending Modula-2 to build large Integrated Systems" IEEE Software November 1986. I am not aware of a comparable rationale for Modula-3. Whereas Modula-2+ is upwards compatible with Modula-2, Modula-3 is not - there are some minor syntactic changes and some fairly fundamental changes in the area of pointers to support "safe programming". Modula-3 objects are a bit like Oberon's Record Extensions (Oberon was Wirth's successor to Modula-2) except that Modula-3 records distinguish data fields from method fields. Unusually, in an object oriented language, the objects are not opaque within the scope of an object type declaration, but it is possible to export a partial type definition from a module and achieve encapsulation that way. (In C++ terms, all fields are public and all functions are virtual). Another unusual feature is that the method fields of an object can be specified as each instance of the object is created but defaults are allowed. This overview is perhaps a bit too brief for you but I hope it is helpful - mail me if you don't get something better. Cheers. Robert Stroud, Computing Laboratory, University of Newcastle upon Tyne. EMAIL R.J.Stroud@newcastle.ac.uk ----------------------------------------------------------------------------- From: woolsey%mri%sun0@ames.arc.nasa.gov (Jeff Woolsey) Well, here are the syntactic differences I found. One of my gripes was addressed in the 12 Changes. The major difference between the languages, though is that Modula-3 has OBJECTs. Other significant differences appear in the way that strings are handled. Wed Aug 1 12:03:54 PDT 1990 Notes on converting Modula-2 programs to Modula-3. value Modula-2 form Modula-3 form Syntactic differences ========= =========== + 100B 8_100 = 34C '\034' = 'STRING' permitted "STRING" - '''' '\'' - '"' '\"' - """" "\"" - "'" "\'" = <> # - ;; missing = ODD(x) (1 = x MOD 2) = INCL(set, elt); set := set + S{elt}; = EXCL(set, elt); set := set - S{elt}; = TYPE COLOR=(RED, BLUE, GREEN) TYPE COLOR={RED, BLUE, GREEN} + WITH record DO x(field) END WITH y=record.field DO x(y) END = CASE x OF 4: END CASE x OF 4 => END + PROCEDURE X(A: CHAR); PROCEDURE X(A: CHAR)= = PROCEDURE X; PROCEDURE X()= = X; X(); = POINTER TO REF = CHR(x) VAL(x, CHAR) = IMPLEMENTATION MODULE x; MODULE x; = DEFINITION MODULE x; INTERFACE x; = HALT missing, exception? = PROCEDURE X() END X; PROCEDURE X()= BEGIN END X; = MODULE X; MODULE X EXPORTS Main; Semantic differences ======== =========== - "LITERAL" = ARRAY OF CHAR "LITERAL" = TEXT = CARDINAL=[0..2*LAST(INTEGER)+1] CARDINAL=[0..LAST(INTEGER)] = RECORD CASE BOOLEAN OF END END missing ? IMPORT COLOR; RED IMPORT COLOR; COLOR.RED Apparent bugs in SRC Modula-3 1.4 ======== ==== == === ======== === LAST(INTEGER)+LAST(INTEGER)+1 does not generate a checked runtime error. This is listed in the release notes. Null statements ;; driver the parser batty. The compiler fails with an assertion botch that has something to do with passing TEXT to PROCEDUREs that want ARRAY OF CHAR. Fixed in 1.6. Opinions ======== TEXT appears to be a botch. String literals, "hi there", are of type TEXT, and this is what a lot of procedures want as parameters, but I cannot index a TEXT variable (being opaque I can't dereference and index it either, even if I know what it is). I usually end up mirroring such a variable with a TEXT version and an ARRAY OF CHAR version. There HAS to be a better way. IMPORT TextF addresses a lot of this, but is not complete. Still no module-termination code. May be able to finagle it with exceptions. Jeff Woolsey Microtec Research, Inc. ..!amdcad!sun0!woolsey +1 408 980 1300 x585 -----------------------------------------------------------------------------