Passing Connections as Parameters

There are two methods of passing a connection as a parameter to a procedure: using a formal parameter based on a particular connection block, or using a parameter of type CONNECTION. The following table compares these two methods:

 

Formal Parameter Based on Connection Block

Formal Parameter of Type CONNECTION

Language Support

ALGOL and NEWP

ALGOL and NEWP

Actual Parameter

Must be based on a connection library type specified by the formal parameter.

Can be a connection of any connection library.

Connection Objects

In ALGOL, provides access to procedures declared in the connection block.

In NEWP, provides access to any object declared in the connection block.

Does not provide access to connection objects.

Library Attributes

Provides access only to STATE attribute.

Provides access only to STATE attribute.

Parameters to Library Procedures

Cannot be used as a formal parameter to an imported or exported procedure.

Can be used as a formal parameter to an imported or exported procedure.

Connection Parameters Example

The following NEWP program illustrates both of these methods of passing connections as parameters:

100 BEGIN                                      
110                                            
120 TYPE CB1_TYPE = CONNECTION BLOCK           
130    BEGIN                                   
140    PROCEDURE PROC1;                        
150       IMPORTED;                            
160    END;                                    
170                                            
180 TYPE CB2_TYPE = CONNECTION BLOCK           
190    BEGIN                                   
200    PROCEDURE PROC2(CLE);                   
210       CONNECTION CLE;                      
220       IMPORTED;                            
230    END;                                    
240                                            
250 CB1_TYPE LIBRARY LIB1(LIBACCESS = BYTITLE, 
260                  CONNECTIONS = 9,          
270                  TITLE = “OBJECT/LIB1.”);  
280                                            
290 CB2_TYPE LIBRARY LIB2(LIBACCESS = BYTITLE, 
300                  CONNECTIONS = 3,          
310                  TITLE = “OBJECT/LIB2.”);  
320                                            
330 PROCEDURE PROC3(CB);                       
340       CB1_TYPE CB;                         
350    BEGIN                                   
360    INTEGER I;                              
370    I := LIBRARY(CB).STATE;                 
380    IF I = VALUE(LINKED) THEN               
390       CB.PROC1;                            
400    END;                                    
410                                            
420 PROCEDURE PROC4(CN);                       
430       CONNECTION CN;                       
440    BEGIN                                   
450    INTEGER I;                              
460    I := CN.STATE;                          
470    END;                                    
480                                            
510 LINKLIBRARY(LIB1[0]);                      
520 LINKLIBRARY(LIB2[0]);                      
530 PROC3(LIB1[0]);                            
540 PROC4(LIB1[0]);                            
550 PROC4(LIB2[0]);                            
560 LIB2[0].PROC2(LIB1[0]);                    
570                                            
580 END.                                      

Explanation of Example: Connection Block Parameter

In this example, procedure PROC3 (at line 330) declares a parameter CB that is based on connection block CB1_TYPE. As a result, statements in PROC3 are able to read the STATE attribute of the connection, and to initiate procedure PROC1 (which is declared in CB1_TYPE). However, the statement at line 530 that invokes PROC3 must pass a connection of a library (LIB1) that is based on CB1_TYPE. This statement could not have passed a connection of LIB2, because LIB2 is based on a different connection block type.

Explanation of Example: CONNECTION Parameter

Procedure PROC4 (at line 420) declares a parameter of type CONNECTION. As a result, this procedure cannot include any statements invoking procedures declared by the connection. On the other hand, PROC4 can receive connections from libraries based on different connection blocks. Thus, the statements at lines 540 and 550 pass connections of LIB1 and LIB2, which are based on two different connection block types.