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=2.0 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab436e97ff76821f,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.228.227 with SMTP id sl3mr22807564pbc.5.1341876477800; Mon, 09 Jul 2012 16:27:57 -0700 (PDT) Path: l9ni11278pbj.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Does Ada need elemental functions to make it suitable for scientific work? Date: Mon, 09 Jul 2012 18:27:54 -0500 Organization: Aioe.org NNTP Server Message-ID: Reply-To: nma@12000.org NNTP-Posting-Host: 6hm90iByl0ABMIk4viG5Dw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-07-09T18:27:54-05:00 List-Id: I have been trying Ada to see how suitable it is for computational work (I am studying finite elements, and wanted to try Ada for basic programs). And even though I find its type system a great asset to help catch many errors, I find it a little awkward for programming on arrays and matrices which ones does alot in scientific numerical programming. The most important feature which I found missing is that Ada functions do not automatically work on arrays and matrices. In Fortran, we see http://en.wikipedia.org/wiki/Fortran_95_language_features#Elemental_operations.2C_assignments_and_procedures "Most intrinsic functions are elemental and Fortran 95 extends this feature to non-intrinsic procedures" intrinsic functions in Fortran are those build-in (like sin/cos, etc...) Lets look at a very simple example to help explain what I mean. I wanted to raise each entry in a vector to the second power. In Fortran, I can just write V**2, where V is a vector. In Ada, I can't do that. Since ** is not defined on this array type and this number type. I would have to write a loop to iterate over V and do V(I)**2 on each element. This for me, is a step backward. This is how Fortran77 was. I know I am a newbie in Ada, and I could have overlooked a simple solution to do this. But I really do not want to write packages and define operators each time and for each type I make to have it work as elemental function each time. This is something that should be build into the language. Here are two complete trivial examples of what I mean. I was wondering if there is a chance that something like this can be added to Ada like what was done for Fortran? ---- fortran ------------------------- !-- showing how to use Fortran for vectored operations !-- equations work on vectors, no need for loop program f08 implicit none integer, parameter :: N = 7 real , parameter :: D(N) = [-0.2,1.0,1.5,3.0,-1.0,4.2,3.1] real , parameter :: H(N) = [2.1,2.4,1.8,2.6,2.6,2.2,1.8] real :: V(N) V = D**2 * H ! all vectored operations print *, v end program f08 --------------------------------- >gfortran f08.f90 >./a.out 8.39999989E-02 2.4000001 4.0499997 23.400000 2.5999999 38.807995 17.297998 ---------Ada ------------------ procedure foo2 is N : integer :=7; type array_t is array(1..N) OF float; D : constant array_t :=(-0.2,1.0,1.5,3.0,-1.0,4.2,3.1); H : constant array_t :=(2.1,2.4,1.8,2.6,2.6,2.2,1.8); V : array_t; begin V := D**2 * H; end foo2; ------------------- >gnatmake foo2.adb gcc -c foo2.adb foo2.adb:11:10: invalid operand types for operator "**" foo2.adb:11:10: left operand has type "array_t" defined at line 4 foo2.adb:11:10: right operand has type universal integer gnatmake: "foo2.adb" compilation error > --Nasser