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!reader02.eternal-september.org!feeder.eternal-september.org!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Record operations (Algebraic Data Types and printing) Date: Fri, 5 Oct 2018 21:32:57 +0300 Organization: Tidorum Ltd Message-ID: References: <0f5608ef-0038-491c-b15f-f67bcc76fae8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net X4BpKd9/iI+QTGE9xB6TCAMQSLXuppR095WGbjFuj0daBLqZBA Cancel-Lock: sha1:4+wODmeFXUOwcr5FKEfiVpltDL4= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <0f5608ef-0038-491c-b15f-f67bcc76fae8@googlegroups.com> Xref: reader02.eternal-september.org comp.lang.ada:54490 Date: 2018-10-05T21:32:57+03:00 List-Id: On 18-10-05 20:46 , Henrik Härkönen wrote: > Hi! (Very) Slowly getting my Ada wheels rolling, didn't get the book > yet etc. but anyway... > > I'm coming from Scala world most recently and I like to leverage > Algebraic Data Types (through sealed traits), or Discriminated > Unions, as they were called in F#. I was happy to find out that Ada > has Variant Record, which I believe pretty much covers the same > thing. Maybe in a bit more verbose way. :) I'm somehow fascinated by > the possibility to carry state as the type, thus with different data > items for each state. > > Now as I'm playing with the records, I'd like to print them out, just > for "debugging" purposes. Is there any convenient way to splash them > out in console? Some sort of default string representation? Nope, and too bad. That's something that would often be useful at the program development stage. But not so useful when the program is in production runs, for typical Ada applications. One way to get something like this is to run the program under a debugger, and ask the debugger to display the record variable. Debuggers can usually show "component-name = value" pairs. > Seems that 'Image attribute works only for scalar types. Indeed. I seem to remember seeing a posting here, a few years ago, offering a tool that would construct an Image function for a given record type. The tool was possibly based on ASIS, and possibly not. Sadly I did not find any links to this, but perhaps someone else has a better memory or better search methods. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .