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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c689b55786a9f2bd X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!usenet-fr.net!gegeweb.org!aioe.org!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: for S'Image use Func?? Date: Thu, 06 May 2010 20:14:33 +0200 Organization: Ada At Home Message-ID: References: NNTP-Posting-Host: DJZgmzaid83pf9t7o+DBhw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Opera Mail/10.53 (Win32) Xref: g2news2.google.com comp.lang.ada:11333 Date: 2010-05-06T20:14:33+02:00 List-Id: Le Thu, 06 May 2010 19:10:20 +0200, Warren a =C3=A9cr= it: > I have tried to google for this and have not yet found > a suitable answer, so I'll troll, er, poll for an > answer here.. > > Is there the ability to substitute your own S'Image > function? For example, a basic interpreter might > define: > > type LNumber_Type is range 0..99_999; > > Can I declare.. > > for LNumber_Type'Image use LNumber_To_String; > > If so, then the question is what the signature of > the S'Image function looks like-- is it: As far as I could tell, your intuition is good, as there is indeed such = = things in Ada, called either representation clauses or operational = clauses. See [ARM 2005 13.3] for more about it. An excerpt to be kind: [ARM 2005 13.3 (2)] attribute_definition_clause ::=3D for local_name'attribute_designator use expression; | for local_name'attribute_designator use name; [ARM 2005 13.3 (4)] For an attribute_definition_clause that specifies an attribute that = denotes a subprogram, the expected profile for the name is the profile = required for the attribute. However, it later says: [ARM 2005 13.3 (5/1)] An attribute_designator is allowed in an attribute_definition_clause onl= y = if this International Standard explicitly allows it Comes with a tiny example: [AARM 2005 13.3 (6a)] Ramification: This implies, for example, that if one writes: for T'Read use R; R has to be a procedure with two parameters with the appropriate subtype= s = and modes as shown in Finally, it should be checked if Image is explicitely allowed as an = attribute designator for an operational clause (I may check later to giv= e = you a more formal answer to this one question). I use representation clauses from time to time, but I've never used this= = kind of one, for the reason I give you right after now. > function LNumber_To_String(LNO : LNumber_Type) return String; > > Finally, there is actually a third question- more along > the lines of "Should this language feature be used > in this manner?", or is it preferable to just code your > own along the lines of (which is what I presently use): > > function To_String(LNO : LNumber_Type) return String; > > Inquiring minds need to know, > > Warren I would say, it is more handy to define a function, because a function = would be able to hold the exact formatting parameter your application = requires, it would be able to hold the exact optional defaults for those= = parameters and it would better integrates with the overall general desig= n = of an Ada application, that, =E2=80=9Cwithing=E2=80=9D package and using= renames clause. = Using attribute, you are require to always use thye type name as a prefi= x = for such things as =E2=80=99Image. With function, you may =E2=80=9Cwithe= d=E2=80=9D the package = defining this function, and make it part of the local scope using = something like =E2=80=9Cfunction F (...) ... renames My_Package.F ...=E2= =80=9D. More handy IMHO. All of this providing I've understood what you were requesting for. -- = No-no, this isn't an oops ...or I hope (TM) - Don't blame me... I'm just= = not lucky