Can TPB be defined outside defining modules? 
Author Message
 Can TPB be defined outside defining modules?

Hello,

I have the following question which answer I can't find in the Oberon-2
report. I might have overlooked something. If so, please let me know
without flaming me.

The question is:
  Can you define a Type-Bound-Procedure outside of the module in which
  an object is defined:

  MODULE Test;
  TYPE PO* = POINTER TO TO;
  TO* = RECORD
         a*: INTEGER
        END
  END Test.

  MODULE Use;
  IMPORT Test;
  PROCEDURE (this: Test.P0) UseIt;
  BEGIN
    ... do something with this.a ...
  END
  END Use.

This would imply that if you don't export a, you could not use it in the
typebound procedure. Am I right? I believe the Oberon-compiler rejects
putting typeboundprocedures in other modules.

Thanks for helping me,
  Rob Knubben

-----------------------------------------------+-------------------------------


AB: -There were some pretty strange neighbors. | Rob Knubben
    ( AB: Annie Blackburne [Heather Graham]    | Student Computing Science
      DC: Dale Cooper [Kyle MacLachlan]        | Eindhoven University of
         -- Twin Peaks -- )                    |   Technology, The Netherlands.



Mon, 07 Oct 1996 17:40:22 GMT  
 Can TPB be defined outside defining modules?

Quote:

>The question is:
>  Can you define a Type-Bound-Procedure outside of the module in which
>  an object is defined:

From the Oberon Report: 10.2 Type-bound procedures

Procedures may be associated with a record type declared in the same module.

Quote:
>This would imply that if you don't export a, you could not use it in the
>typebound procedure. Am I right? I believe the Oberon-compiler rejects
>putting typeboundprocedures in other modules.

That's correct. If you don't export a field of a record, you're not allowed to
use it, not even in TB procs outside the defining module.

A technical explanation for the "restriction" is:
The module defining a type is also responsible for allocating the type
descriptor including the offset table for the TB procs. If you declare new TB
procs outside the original module, how can you then guarantee that the offsets
in the type descriptor are correct?

Regards,


  Institute for Computer Systems
  Swiss Federal Institute of Technology (ETH)
  CH-8092 Zurich, Switzerland



Mon, 07 Oct 1996 21:24:45 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. shadows of define and define-syntax

2. define in define-syntax

3. define-macro -> define-syntax

4. is define-syntax inside define-syntax OK?

5. define-macro vs define-syntax

6. Define in a define

7. Defining define (possibly a mad question)

8. Scheme macro source: define/keyed, for defining keyword-triggered arguments

9. Macros defining macros with define-syntax

10. Simple persistent object storage: seeking advice on storing user defined, runtime defined abstract datatypes into Oracle

11. #define python-list@python.org '#define'

12. &whole, defsetf, define-setf-method, define-setf-expansions, &environment and other Lispy Questions

 

 
Powered by phpBB® Forum Software