Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!bloom-beacon!oberon!cit-vax!ucla-cs!zen!ucbvax!ECNCDC.BITNET!MSRS002 From: MSRS002@ECNCDC.BITNET.UUCP Newsgroups: comp.lang.modula2 Subject: Procedure Types & Variables Message-ID: Date: Wed, 30-Sep-87 23:15:00 EDT Article-I.D.: UCF1VM.INFO-M2%87093023534491 Posted: Wed Sep 30 23:15:00 1987 Date-Received: Sat, 3-Oct-87 01:57:21 EDT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Info-Modula2 Distribution List Distribution: world Organization: The ARPA Internet Lines: 67 not be using any normal I/O modules, indeed, it may be some burried program for which the term I/O doesn't really apply. Anyhow, the module which was called outside its environment would take some sort of exception. It would be perfectly acceptable to allow this sort of call if the procedure being called did not reference any variables global to itself, except perhaps variables defined in the module itself. Any thoughts on this matter? R Rec Recurs Recursive Recursively yours, Tom Ruby MSRS002@ECNCDC Modula allows a variable to be a procedure type, and that variable to be assigned the "value" of different procedures. This is a very usefull thing when making programs such as operating systems or I/O drivers, but it leads to one question. Consider the following scrap of code: PROCEDURE A ; VAR P : PROC ; PROCEDURE B ; VAR X : CARDINAL ; PROCEDURE C ; BEGIN X := 17 ; END C ; BEGIN P := C ; END ; BEGIN B ; P ; END A ; Now, I realize this wouldn't compile because I forgot to say END B, but once that was finished, what would you expect to happen at run time? When procedure C assigns the value 17 to X, X does not exist because the activation record for B does not exist. I haven't actually tried this on any compilers, but I would expect the same sort of "crash" as you get when you assign a value to a dereferenced pointer after the pointer has been de-allocated, that is, you set some word in memory to 17, and nobody really knows what word that is. I can think of a device to catch this error, if it is considered an error. Each procedure would be assigned a unique number by the compiler, and this number would be placed in the activation record at run time. When a procedure is entered, either directly or through a variable, it would check the activation records for procedure numbers to check if it is in the proper environment. If not, it would issue some sort of helpful ( please ) message, then terminate the program. Of course, in Modula, you're not always sure what "Issue a Message" means since the application program may