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: a07f3367d7,380d5dcaa525139c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.180.96.231 with SMTP id dv7mr8372656wib.6.1356837411714; Sat, 29 Dec 2012 19:16:51 -0800 (PST) Path: i11ni337243wiw.0!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: X : Real_Vector := Solve(A => A, X => B); -- Why X as argument name? Date: Mon, 24 Dec 2012 10:33:13 +0200 Organization: Tidorum Ltd Message-ID: References: <871uegmmiq.fsf@katthult.thorslund.org> Mime-Version: 1.0 X-Trace: individual.net O507nEbtN6S3elbOEhc6PAAvgmh2mO1im5C1r1MVWCose2Ouc1WIfISZbmKOZob6i/ Cancel-Lock: sha1:BUzgRouvD6sNzZPSVpe6Onat2lA= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <871uegmmiq.fsf@katthult.thorslund.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2012-12-24T10:33:13+02:00 List-Id: On 12-12-24 00:28 , Gustaf Thorslund wrote: > -- why_x.adb by confused Gustaf Thorslund > > with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays; > with Ada.Text_IO; use Ada.Text_IO; > > procedure Why_X is > -- Let's say we have an equation Ax = b according to the notation > from > -- http://en.wikipedia.org/wiki/Matrix_(mathematics)#Linear_equations > -- where A and b are known while x is unknown. > > A : Real_Matrix(1..1, 1..1) := (others => (others => 2.0)); > B : Real_Vector(1..1) := (others => 12.0); > > -- x is found using > -- function Solve (A : Real_Matrix; X : Real_Vector) return > -- Real_Vector; > X : Real_Vector := Solve(A => A, X => B); -- Why X as argument name? Or you could ask, why use "X" as the name of a local variable? > > begin > for I in X'Range loop > Put_Line(Float'Image(X(I))); > end loop; > end Why_X; > > -- Executing the program gives > -- $ ./why_x > -- 6.00000E+00 > -- So we found the expected value of x. Do you see that as a problem? :-) > -- Was it a misstake to use X as argument name in Solve? Do you mean, is it an error that your program uses "X" as the name of a local variable, when it also calls a function that has a formal parameter called "X"? No, it is not an error and is quite legal. The compiler knows from the named-association syntax ("X => ...") that "X" refers to the name of a formal parameter. Or do you mean to ask if it was a mistake in the definition of Ada.Numerics.Real_Arrays.Solve to give the second formal parameter the name "X", given that "X" is a common name in client code? That is a matter of coding style and habit. (I would probably have chosen the name "B" for the second parameter, since "X" suggests "unknowns" to me, while "A" and "B" suggest "knowns".) And most coding style guidelines recommend against single-letter names like "X" in application programs, so "X" should not really be a common name. Or do you mean to ask if it is mistake that your program uses the name "X" for a local variable, which the reader can confuse with the formal parameter "X"? If you have no important reason to call your local variable "X", it would be slightly clearer to choose a different name, at least for readers not yet familiar with Ada. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .