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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Image attribute (yet again) Date: Mon, 27 Apr 2020 14:33:29 +0200 Organization: Adalog Message-ID: References: <26e971a9-6fcc-4e4c-84ee-d74aecd5b217@googlegroups.com> <2c769c87-72f2-4107-b0bf-3846e3ae6c7a@googlegroups.com> <670160da-e66d-446f-a415-27df39d9a73f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 27 Apr 2020 12:33:29 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="1263240d53307d6969cff5f75e32d03c"; logging-data="9339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19T/YIUQK8HIthN/I+PT82p" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Cancel-Lock: sha1:xhfH/byaTINraSJK1YQ3HrbxBBk= In-Reply-To: <670160da-e66d-446f-a415-27df39d9a73f@googlegroups.com> Content-Language: fr X-Mozilla-News-Host: news://reader80.eternal-september.org Xref: reader01.eternal-september.org comp.lang.ada:58506 Date: 2020-04-27T14:33:29+02:00 List-Id: Le 26/04/2020 à 19:33, Jere a écrit : > I'm not saying it can't be done. I'm saying by the time I go through > all the processing needed, I might as well wrote my own function. It > makes the existing operation mostly useless (unless I just want a > temporary debug print that I don't care how it looks). For example, > if I want to print to a 16x2 character LCD screen and I want to print > 0 padded 4 digit hex values with no "16#" prefix or "#" ending, then > I need to call Put with an 8 character string, search for the first > occurrence of '#' (it can be in multiple locations), then overwrite > a variable number of those characters with 0's (based on the location > of '#'), and then extract the 4 digits I actually need. All doable > (not saying it cannot be done), but at that point, I am better off > just doing my own custom operation instead instead of even using the > Put operation. Right. If you want you own format, write it. It will take you less time than writing this message. For the benefit of everybody, here it is: Hex_Digits : constant array (Bits_16 range 0..15) of Character := "0123456789ABCDEF"; function Hex_Image (Value : Bits_16) return String is Result : String (1 .. 4); Current : Bits_16 := Value; begin for I in reverse Result'Range loop Result (I) := Hex_Digits (Current mod 16); Current := Current / 16; end loop; return Result; end Hex_Image; > It feels like the Put operation wasn't designed > with usability in mind. Just the presence of the "16#" and "#" > around the value makes using the operation more clunky than it > should be. If that had been left out or if the operation at least > allowed for padding the actual numeric value inside the result, > then it would have been much more usable. Text_IO was designed for file operations, not so much for interactive IO. And there is an important feature of Text_IO which is rarely mentioned: If you use only the appropriate operations from Text_IO (no 'Image), and your program writes into a file, you can take the sequence of code that writes the file, replace every Put_* operation by the symetric Get_* operation, and you will read the file without error. This feature requires that if you write a number in a certain base, then you need to recognize the base when reading. So it's not an error, but a design decision. Of course, like any design decision, you may agree with it or not. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr