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=-0.3 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,3e0895d4223034d7 X-Google-Attributes: gid1094ba,public X-Google-Thread: 103376,cfe6bee6cb133ace X-Google-Attributes: gid103376,public From: bglbv@my-dejanews.com Subject: Re: Fortran Myths & Disinformation Wanted Date: 1999/02/13 Message-ID: <87iud6ryr6.fsf@bglbv.my-dejanews.com>#1/1 X-Deja-AN: 444032103 References: <36B9B8FF.4E34BF22@mixcom.com> <36BA1282.41EA5CB3@earthlink.net> <87679g96ye.fsf@bglbv.my-dejanews.com> <36BC008F.6CF45630@earthlink.net> <36BC2658.62C1E14C@erols.com> <36BDAE80.FB135C81@erols.com> <87emo0y8vi.fsf@bglbv.my-dejanews.com> <87g18d3lsv.fsf@bglbv.my-dejanews.com> <36c5a2cc.3411225@news1.newscene.com> Organization: CyberCity Internet Newsgroups: comp.lang.fortran,comp.lang.ada Date: 1999-02-13T00:00:00+00:00 List-Id: cnahr@seemysig.invalid (Christoph Nahr) writes: > >with Ada.Numerics.Elementary_Functions; > >use Ada.Numerics.Elementary_Functions; > Unashamed off-topic question: Why exactly do you have to write *two* > lines to use *one* Ada library? I'm cross-posting this response to comp.lang.ada, where the question would have been on-topic (albeit a FAQ). The answer is: you don't need the second statement ("use") if you only want to use fully qualified names, as in return Ada.Numerics.Elementary_Functions.Sin(G(2.0*X)) - Ada.Numerics.Elementary_Functions.Cos(G(X/2.0)); Likewise, when you only want to import a few selected identifiers from the with'ed package, you can simply give them shorthand names: function Sin (X: Float) return Float renames Ada.Numerics.Elementary_Functions.Sin; -- and likewise for Cos One can also do the renaming at a higher level: package EF renames Ada.Numerics.Elementary_Functions; -- ... return EF.Sin(G(2.0*X))-EF.Cos(G(X/2.0)); An additional twist is that you can (indeed must) "with" a package at the compilation unit level, but are allowed to "use" it only within more limited scopes. > Clumsy attempt to make this question on-topic: After all, Fortran > 90/95 only has the USE statement and seems to do fine. :-) That's one of the things the committee that developed Fortran 90 tried to keep simple. They were well aware of Ada 83 syntax at the time. Whether the adopted solution is appropriate is (as always) debatable. Suffice it to say that Fortran did not go for the hierarchical naming scheme of Ada, and that once you remove that feature the distinction between "with" and "use" becomes blurred. On the other hand, Fortran offers renaming and ONLY: clauses on the USE statement (and nowhere else). Also, Fortran defaults to reexporting objects that are visible by use association within a module; you have to explicitly make them PRIVATE to prevent this. By contrast, Ada packages won't reexport such entities unless they've been explicitly renamed within the package. Fortran lets you put a damper on namespace pollution through ONLY: clauses on USE statements and through the PRIVATE attribute, while Ada does that by defaulting to a fully qualified hierarchical namespace and giving you a couple of ways of creating abbreviations, namely "use" and "renames". Neither solution is perfect, but both are workable in practice. Since this is going to two newsgroups whose readers need not all be familiar with both Ada 95 and Fortran 95, a few examples may be useful. ! Fortran -- Ada MODULE inner package Inner is PUBLIC REAL :: a, b, c A, B, C: Float; END MODULE inner end Inner; with Inner; MODULE middle package Middle is USE inner, ONLY: a, d => c A: Float renames Inner.A; D: Float renames Inner.C; PUBLIC INTEGER :: c C: Integer; END MODULE middle end Middle; with Middle; MODULE outer package Outer is USE middle use Middle; -- optional PRIVATE PUBLIC :: c C: Integer renames Middle.C; LOGICAL :: b B: Boolean; END MODULE outer end Outer; There. I hope I got it all right (my Ada is a bit rusty). If not, someone will undoubtedly correct me. The point is that both languages offer comparable facilities, but there are differences of detail. I'm not really interested in passing judgment on which is better. Give that apple to Paris, not to me. Note that in the example above, INNER exports A, B, C; MIDDLE exports INNER's A and C (renamed D) and MIDDLE's C; OUTER exports OUTER's B and MIDDLE's C.