Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: Ordinal sch...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 174 of 211
Post > Topic >>

Re: Ordinal schema in EP

by John Reagan <john.reagan@[EMAIL PROTECTED] > Oct 26, 2005 at 03:10 PM

Waldek Hebisch wrote:
> John Reagan <john.reagan@[EMAIL PROTECTED]
> wrote:
> 
>>
>>Why do you care about the type of C1 and C2?
>>
> 
> 
> I want to faithfully implement EP typechecking rules.
>  

For schematic ordinals, should be pretty straight forward.  The fact 
that assignment-compatability is pretty loose with ordinal values, there 
isn't much that can go wrong.

> 
>>You can't have more than one definition of C1 and C2 in any region, can 
>>you?  It should all just work out.
>>
> 
> 
> But I can have multiple types produced from the same schema in the same
> region. I can export renamed C1 and C2 from a module, and then import
> different versions in a single region. I can pass C1 to a procedure
> with schematic value parameter and inquire about it type. I can get 
> from C1 corresponding discriminat value. For example:
> 
> procedure p;
>   var va2 : es(2);
>   procedure tc(par : es);
>     var va1 : type of par;
>   begin
>     va1 := c1;
>     writeln(va1.i);
>     va2 := va1;
>   end;
> begin
>   va2 := c2;
>   tc(c1)
> end;

Have your read the NOTE in section 6.7.3.2?  It doesn't explicitly 
mentioned enumerated-types, but since enumerated-types behave very much 
like subrange-types when it comes to doing assignment-compatability, I 
believe that the NOTE applies to them as well.

Here is what my compiler does for your above example:

$ type es.pas
program foo(input,output);

type es(i:integer) = (c1,c2);

procedure p;
  var va2 : es(2);
  procedure tc(par : es);
   var va1 : es(par.i);
   begin
   va1 := c1;
   writeln(va1.i);
   va2 := va1;
   end;
  begin
  va2 := c2;
  tc(c1);
  end;

begin
p;
end.


$ pascal/check es

  tc(c1);
.....^
%PASCAL-E-OPNDASSCOM, Operands are not assignment compatible
-PASCAL-I-NOACTCOM, No actuals are compatible with schema formal parameter
at line number 16 in file HIYALL$:[REAGAN]ES.PAS;1
%PASCAL-E-ENDDIAGS, PASCAL completed with 2 diagnostics

(Personally, I don't like TYPE OF.  It isn't needed since you can
use the discriminant of PAR to define VA1.  TYPE OF is only really 
useful when combined with unextended Pascal's conformant array
parameters.)

>   
> All would be clear if the constants c1 and c2 are defined in the process
> of discriminating the schema. Then tc would print 2. However, if c1 and
> c2 are defined by the schema definition (which is my literal reading
> of the standard) then it is not clear what value tc should print (and
> in particular if the above is legal).
> 
> Or put it differently:
> 
> var v2 : es(2);
>     v3 : es(3);
> begin
>   v2 := c1;
>   v3 := c1;
> end;
> 
> Is the above legal? 

Yes it is.

If c1 and c2 are defind by the schema definition
> then nothing stops as from producing many different types from the
> schema. On the other hand for the first assignment to be valid v2 and c1
> must be of the same type while for the second assignment to be valid v3
> and c1 must be of the same type. Since v2 and v3 have different types
> so one of the assignment must be illegal.

But remember that the ordinal expression on the right side gets promoted 
to the underlying base type.

It isn't much different than:

var v2 : 1..100;
     v3 : 5..75;
begin
v2 := 50;
v3 := 50;
end;

The value 50 can be assigned to a variable of type "1..100" and also to 
a variable with type "5..75".

In a somewhat related topic, in one of the early Extended Pascal drafts, 
we allowed "TYPE OF" to be used on a constant.  Besides the hard 
questions like what is the result of "TYPE OF 1", it was really a pain 
to define TYPE OF NIL, TYPE OF [] and TYPE OF "".  We decided that it 
wasn't worth our effort to try to construct a type universe where these 
made sense so we removed TYPE OF constants in the final draft.  Again, 
as I don't like TYPE OF at all, I tried to remove it entirely.

> 
> Again, if we decide that discriminating schema defines c1 and c2 then
> already declaration of v3 is illegal (because of duplicate definition
> of c1 and c2).

The discrimination doesn't define C1 and C2, the schema definition 
defines C1 and C2;

Again, no different than the error when you do

type rec1 = record f1 : (c1,c2); end;
      rec2 = record f2 : (c1,c2); end;

$ pascal/check es

      rec2 = record f2 : (c1,c2); end;
..........................^
%PASCAL-E-REDECL, A declaration of C1 already exists in FOO
at line number 4 in file HIYALL$:[REAGAN]ES.PAS;2

      rec2 = record f2 : (c1,c2); end;
.............................^
%PASCAL-E-REDECL, A declaration of C2 already exists in FOO
at line number 4 in file HIYALL$:[REAGAN]ES.PAS;2
%PASCAL-E-ENDDIAGS, PASCAL completed with 2 diagnostics


> 
> Now, if we decide that discriminating schema defines enumeration
constants,
> then it in natural tu appropriate exception to 6.2.2.7 like:

But they dont.


-- 
John Reagan
HP Pascal/{A|I}MACRO for OpenVMS Project Leader
Hewlett-Packard Company




 5 Posts in Topic:
Ordinal schema in EP
Waldek Hebisch <hebisc  2005-10-21 14:04:44 
Re: Ordinal schema in EP
John Reagan <john.reag  2005-10-24 16:02:55 
Re: Ordinal schema in EP
Waldek Hebisch <hebisc  2005-10-24 21:32:07 
Re: Ordinal schema in EP
John Reagan <john.reag  2005-10-26 15:10:32 
Re: Ordinal schema in EP
Waldek Hebisch <hebisc  2005-11-10 02:14:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:33:56 CDT 2008.