home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!utcsri!torn!spool.mu.edu!wupost!darwin.sura.net!newsserver.jvnc.net!netnews.upenn.edu!dsinc!ub!csn!teal.csn.org!sullivan
- From: sullivan@teal.csn.org (Steve Sullivan)
- Newsgroups: comp.lang.modula3
- Subject: structural equivalence ==> no referential transparency
- Message-ID: <C1DAw0.ILz@csn.org>
- Date: 24 Jan 93 16:52:42 GMT
- Sender: news@csn.org (news)
- Distribution: na
- Organization: Colorado SuperNet, Inc.
- Lines: 48
- Nntp-Posting-Host: teal.csn.org
-
-
- In Modula 3, arrays lose all index info when passed to a subprocedure.
- For example, an array dimensioned [1:10] becomes [0:9] in a called proc.
-
- This is a real lack of referential transparency:
- vec[1] means different things, depending on which proc it appears in.
- If a caller passed an array and an index value of some element
- to a subproc, the index value would be invalid in the subproc.
- For example:
-
- Main proc:
- avec: ARRAY {1..100} OF LONGREAL;
- ...
- x = subproc( avec, k);
-
- subproc( avec, k):
- v = avec[k] (* will access element k+1 *)
-
- Although Modula 3 does have FIRST and LAST functions, they
- seem more like afterthoughts than features: even if the
- above subproc were coded v = avec[FIRST(avec)-1+k],
- the subproc must still know the base of avec (hardcoded as "1").
- And in any event "avec[FIRST(avec)-1+k]"
- is far less clear to the reader than "avec[k]".
-
- I don't know, but I assume the designers did this:
- 1. To further the "structural equivalence" concept:
- that all arrays of reals are identical, whether the indices
- of the arrays ints, or an enumerated set.
- 2. To avoid headaches in dealing with enumerated index sets.
-
- However, for me their decision
- not only invalidates all use of enumerated index sets (they
- can't be used in subprocs), but destroys the usefulness of
- subprocs for handling arrays of any sort.
-
- A better approach, in my mind,
- would have been to store a pointer to the definition
- of the enumeration with each array whose index set is drawn from it.
- That way they would main referential transparency.
-
- Does anyone know why the Modula 3 designers created such
- an unwieldy definition for array handling? Is there any
- thought of changing it?
-
- Steve Sullivan
- Grad Student, Dept Computer Science, Univ Colorado Boulder
- sullivan@csn.org
-