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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4f316de357ae35e9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-02 06:59:00 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dennison@telepath.com (Ted Dennison) Newsgroups: comp.lang.ada Subject: Re: FAQ and string functions Date: 2 Aug 2002 06:59:00 -0700 Organization: http://groups.google.com/ Message-ID: <4519e058.0208020559.63f58040@posting.google.com> References: <20020730093206.A8550@videoproject.kiev.ua> <4519e058.0207300548.15eeb65c@posting.google.com> <29e5ffff.0207302052.465a3193@posting.google.com> <4519e058.0208010809.6a4c5e22@posting.google.com> <29e5ffff.0208011621.3193755f@posting.google.com> NNTP-Posting-Host: 65.115.221.98 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1028296740 716 127.0.0.1 (2 Aug 2002 13:59:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 2 Aug 2002 13:59:00 GMT Xref: archiver1.google.com comp.lang.ada:27612 Date: 2002-08-02T13:59:00+00:00 List-Id: bam@snoopy.apana.org.au (Brian May) wrote in message news:<29e5ffff.0208011621.3193755f@posting.google.com>... > There is a replace function for the strings, I am a bit doubtful > though if > you can use it to expand the size of a fixed string... To do that kind of thing, you will generally need to use slicing and catenation ("&"). This is not really "expanding the size of a fixed string", its creating a new (possibly fixed) string based on an old one. Recursion is often useful for this kind of thing. For instance (warning: not compiled or tested): function Transform (Source : String; From_Pattern : String; To_Pattern : String) return String is -- Find the location of the source pattern Pattern_Start : constant Natural := Ada.Strings.Fixed.Index (Source => Source, Pattern => From_Pattern); begin if Pattern_Start = 0 then return Source; else -- Return the string before the pattern, the new pattern, and a -- transformation of the string after the pattern. return Source (Source'First..Pattern_Start - 1) & To_Pattern & Transform (Source (Pattern_Start + From_Pattern'length .. Source'last), From_Pattern, To_Pattern ); end if; end Transform; > > I'm not a big fan of these kinds of renames. Why not instead just > > write: > > > > Put_Line (Class_Name (Package_ID, Get_Attribute (Value (I), "ref")) & > > "($1,$2,$3)"); > > Because if I need to use it multiple times, I think that means it will > have to call get_attribute multiple times, won't it? Quite true. I only said this because each was only used once in the code you presented. If you needed multiple calls to Get_Attribute with the same parameters (presumably returning the same result), then assigning that result into a constant once would probably be better. > Besides, I don't think the above makes it very clear what the > significance > is of the results of each function call. Fair enough. But as someone reading your code the first time, I have to say I found your transformation more confusing than the original. Perhaps that's just me though... > > If you insist in splitting it up, turn those renames into constants. > Are constants better then renames? If so, why? The problem with renames is that they can easily lead to aliasing. You might end up having accesses, or worse, updates, or even *both*, to both the original version and the aliased version. That kind of thing makes it really difficult to follow data flow in your program. In the case of renamed functions, it also obfuscates control flow.