From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7b5b3c67aa2a73fe X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Easy question about Character manipulation Date: Tue, 30 Jan 2007 17:05:31 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1170100860.762334.13830@l53g2000cwa.googlegroups.com> <1d5n0ksoz75yy.3t2hhxjr35fq$.dlg@40tude.net> <1170106218.6329.63.camel@localhost> <1170121405.6329.89.camel@localhost> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1170194735 32748 192.74.137.71 (30 Jan 2007 22:05:35 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 30 Jan 2007 22:05:35 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:D4xrquanhUXr87S6ymlugt8A4hM= Xref: g2news2.google.com comp.lang.ada:8753 Date: 2007-01-30T17:05:31-05:00 List-Id: "(see below)" writes: > Bob Duff asked: > >>> T = 1 .. 3; >>> S = 1 .. 3; >> >>> This is not a matter of type equivalence, >>> it is a matter of automatic type conversion on assignment >>> (assignment compatibility), and that IS unlike Ada, of course. >> >> What about parameter passing? I was under the impression that one can >> pass something of type T to a parameter of type S, or a parameter of >> type Integer, or vice versa, in Pascal. Please correct me if I'm >> wrong. > > It depends on whether they are value parameters or var (-iable) parameters. Interesting. Most parameters are 'in' parameters in Ada, or value parameters in Pascal. But what's the story with 'var' parameters in Pascal? If we have: type T = 1..10; procedure P(X: var T); var A : 1..10; type S = 1..10; var B : S; var C : 1..12345; is it legal to pass A, B, and/or C to P's X, in Pascal? > Value parameters are in effect assigned their values, > and the permissive semantics of assignment compatibility apply; > var parameters must be of equivalent types, and type-equivalence in > ISO Pascal is name-equivalence. ...which seems to say that B and C are illegal above. That's a surprise to me. In case I get accused of being off-topic by discussing Pascal in an Ada newsgroup: I note that 'in out' in Ada is roughly equivalent to 'var' in Pascal, but 'in out' can be passed by copy, whereas Pascal requires pass by reference (which has both good and bad points!). > Caveat, type B in: > > type B = A; > > *is* name-equivalent to A when A is a type-identifier. ...which means that "name equivalence" is a misnomer in Pascal, as it is in Ada (with some types being anonymous in both languages). > In Pascal this syntax is somewhat like: > > subtype B is A; > > in Ada, whereas: > > type B = > > is more like: > > type B is > > in Ada. True, except for implicit conversions. >> If I'm right on that point, then I claim that we're just arguing over >> terminology: saying "so-and-so are different types, but there are all >> kinds of implicit conversions" amounts to roughly the same thing as >> "so-and-so are the same type". > > It is unfortunate that the examples being used are subranges, > because the assignment compatibility rules for subranges are > the most lax. This complexity in the semantics of Pascal > is necessary because it lacks the concept of a subtype, and > is forced to smuggle in something of the facility by rather > ad hoc special rules. So to a small extent your claim is valid. That is, "small extent" means "true for integers, but not true for records". Right? > One of the nicest things about Ada is how it cleared this mess up. Right. I think the Ada "subtype S is Integer range 1..10" is pretty close to Pascal's "type S = 1..10", but Pascal has no rough equivalent to Ada's "type T is range 1..10". True? > That said, there aren't "all kinds of implicit conversions", > Pascal isn't C or PL/1! Indeed! I did not intend to impugn Pascal in that way. I just meant to say that there are different ways of defining semantics that amount to the same thing. >> The point is, if you say this in Ada: >> >> type T1 is range 1..10; >> type T2 is range 1..10; >> X : T1; >> Y : T2; >> >> is there any equivalent in Pascal that causes "X := Y" to be illegal >> (or similarly for parameter passing)? > > For this example, in Pascal the assignment passes type-checking, > as would passing X to a formal value parameter of type T2, > and Y to a formal value parameter of type T1; > but X could only be passed to a formal var parameter of type T1, etc. > > If instead we consider: > > type T1 = record i : integer; end; {or an array, file or pointer type} > T2 = record i : integer; end; {a type that is textually the same} > var X : T1; > Y : T2; > > then X and Y are neither equivalent nor compatible. Thanks for the clarification. - Bob