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,1540032852ee6d61,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!s48g2000cws.googlegroups.com!not-for-mail From: "Jerry" Newsgroups: comp.lang.ada Subject: Why does this work? (overloads) Date: 6 Feb 2007 20:39:23 -0800 Organization: http://groups.google.com Message-ID: <1170823163.681564.186260@s48g2000cws.googlegroups.com> NNTP-Posting-Host: 67.40.87.12 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1170823179 9283 127.0.0.1 (7 Feb 2007 04:39:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 7 Feb 2007 04:39:39 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/420+ (KHTML, like Gecko, Safari/420) OmniWeb/v607.16,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: s48g2000cws.googlegroups.com; posting-host=67.40.87.12; posting-account=Ax24hA0AAABV39UFqUVhb0kauOuAbI3T Xref: g2news2.google.com comp.lang.ada:9044 Date: 2007-02-06T20:39:23-08:00 List-Id: (1) Why does the following work? (2) Have I done something stupid or dangerous? I have written some overloads to +, -, * / to make doing some vector- matrix calculations look more algebraic. I have also made some overloads to allow some element-by-element operations so that I can do Matlab-like things, such as "multiplying" two vectors of the same length and getting a vector back. So here are a few lines of code with a couple declarations from the G.3 Annex of Ada 2005. Note that the line that I originally wrote to test some of these overloads was this, involving some complex entities H := Two_Pi / (Two_Pi + j * Two_Pi * f * x); (j = sqrt(-1.0)) but I think the simplified line for H below captures the essence of my question. Here are a few lines of code. -- From a-ngrear.ads (Ada 2005, Generic Real Arrays -- instanciated with Long_Float)... type Real_Vector is array (Integer range <>) of Real'Base; -- Vectors function "*" (Left, Right : Real_Vector) return Real'Base; -- Inner product -- From some of my own overloads... function "*" (x, y : Real_Vector) return Real_Vector; -- element-by- element function "+" (a : Long_Float; x : Real_Vector) return Real_Vector; -- Some declarations... f, x, H : Real_Vector(0 .. NN - 1); a : Long_Float; -- And finally, two lines of calculation... H := 1.0 + f * x; -- Adds scalar, 1.0, to a vector using my overload above. a := 1.0 + f * x; -- Adds scalar, 1.0, to another scalar, an inner product. I get the results that I expected but I feel a little lucky. Why when calculating H doesn't the compiler interpret f * x as an inner product then generate an error, after adding 1.0, when trying to make the assignment to H which is a vector? Obviously the compiler figures out which of the * operators to use depending on the assigned-to variable. Is this reliable for more complicated calculations? I wonder if it is possible to create an ambiguity that would be resolved "in the wrong way" and I would get incorrect results. Regards, Jerry ___ /o|o\ (o)