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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fd3a5ba6349a6060 X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: should I be interested in ada? Date: 1999/02/23 Message-ID: #1/1 X-Deja-AN: 447641833 References: <7a72e6$g55$1@probity.mcc.ac.uk> <36C93BB4.1429@ecs.soton.ac.uk> <7afc1o$3mi$2@plug.news.pipex.net> <7afttr$7v3$1@nnrp1.dejanews.com> <7aganu$qsc$1@plug.news.pipex.net> <36CC3AEA.59E2@lanl.gov> <7ai502$6an$1@nnrp1.dejanews.com> <36CD8DBA.237C@lanl.gov> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1999-02-23T00:00:00+00:00 List-Id: In article <36CD8DBA.237C@lanl.gov> William Clodius writes: > Perhaps the best simple example is the FORALL statement to do a > reordering of elements > FORALL (I=1:N) X(J(I)) = X(I) > which in Ada would require the explicit creation of a temporary to hold > the value of X, assignment to the temporary, and then the assignment of > the temporary to X. Note it is required that the values of J(1:N) not > duplicate one another and lie within the dimensioned ranges of X. Ignoring for the moment the other discussion on this issue, there are two similar constructs in Ada which have somewhat different restrictions. X := (X(4),X(3),X(2),X(1)); Would reverse the (four) elements of the array X. The problem is that, for this notation, the subscripts are required to be static. You can do: X := (N => 1, others => 0); where N is non-static, or better: X := X(N) & X(P) & X(Q) & X(R); Again the length is set by the syntax, but N,P,Q, and R need not be static. There is a very interesting interaction here between optimization and staticness. Before the assignment happens, the subscripts must be bounds checked, but if their subtype conforms, the check does not need to be done, allowing the assignments to proceed in parallel. Of course, you need to copy the values before writing, otherwise you get junk. Lets go a bit further: X: String := Some_expression; N: Integer range X'Range := ...; X := X(N..X'Last) & X(X'First..N-1); Now the computer can go to town. So Ada does have some idioms that can duplicate part of the functionality of FORALL, but it really would have been nice to add it to Ada 95. Maybe next time. (I never really understood why it didn't make it in. There is a trivial syntax change associated with it, but compilers for low end machines could just treat it like a normal for loop.) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...