🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.modula2
1 messages
1 total messages Started by M. Wille Mon, 05 Oct 1987 07:48
Re: procedure variables ...
#3875
Author: M. Wille
Date: Mon, 05 Oct 1987 07:48
35 lines
1840 bytes
MSRS002@ECNCDC.BITNET writes
>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 B;
   BEGIN
     B; P
   END A ;
  
Do you really think that your code scrap makes any sense. Calling 'C'
outside of its environment does not work in Modula-2. Our compiler
rejects this piece of code, saying that the procedure 'C' in the
assignment 'P := C' is not declared on level 0. Hopefully, other
compilers do the same.

Finally, I will provide you with Wirth's solution of this problem. He
simply restricted the use of assigned procedures to non-local procedures
(see Programming in Modula-2 3rd. Ed., p. 151).
------------------------------------------------------------------
   Matthias Wille             |  CSNET: wille@ifi.ethz.ch
   Institut fuer Informatik   |         wille@komsys.ifi.ethz.ch
   ETH - Zentrum              |  UUCP:  ..mcvax!cernvax!ethz!wille
CH-8092 Zuerich Switzerland   |  Phone: (00411) 256 23 51
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads