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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,24d7acf9b853aac8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.68.MISMATCH!feeder.news-service.com!kanaga.switch.ch!switch.ch!news.belwue.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: S-expression I/O in Ada Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> Date: Sun, 1 Aug 2010 14:53:15 +0200 Message-ID: <1qk2k63kzh7yv$.3jgc403xcqdw$.dlg@40tude.net> NNTP-Posting-Date: 01 Aug 2010 14:53:15 CEST NNTP-Posting-Host: ac48c390.newsspool3.arcor-online.net X-Trace: DXC=2F7I3ihJR;B_cMcF=Q^Z^V3h4Fo<]lROoRa8kFa92CN;AD`]3j X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:12771 Date: 2010-08-01T14:53:15+02:00 List-Id: On Sun, 1 Aug 2010 05:17:45 -0700 (PDT), Natacha Kerensikova wrote: > To describe briefly S-expressions, I consider them to be the simplest > existing data organization beyond raw sequences of bits. They are > basically lists of elements, each element being either a list or an > atom, and atoms being raw sequences of bits. So, it is a tree? > While I'm still not deep enough into Ada to know how to represent the > lists, I guess there won't be major issues, I think I can handle it > myself (though pointers and hints would still be welcome). > > My question here is about how to represent the atoms in Ada. In C it > was merely a void pointer and a size, but it seems more difficult in > Ada because of the strong typing. Because it's up to the application > to make sense (i.e. type) out of the raw sequences of bits in atoms, How can it make sense if the type is unknown? If the type is known, why not to state it? > the S-expression library has to handle them as a sort of untyped > memory chunk. Do you know of a way to handle that? There are many way to do it. 1. Static polymorphism, generics in Ada. The type of the leaves is the formal parameter of the package. 2. Dynamic polymorphism. 2.a. The type of a leaf is class wide, each leaf is derived from some abstract base type. This requires referential approach, i.e. pointers. 2.b. The type of a leaf is a variant type. This is more limiting, but can be by-value. > Please correct me if I'm wrong, but my guess would be that the S- > expression library would provide a Sexp_Atom type, which refers to the > untyped memory chunks, and the application would have procedures to > convert back and forth between Sexp_Atom and whatever types it > internally uses (i.e. serialization and deserialization procedures). I would not do that. > However the library would provide these procedures for the most common > types (e.g. strings and numeric types). > > Though it looks like a fine Ada API (at least to my eyes), I have > absolutely no idea about how to implement the library. How to define > the application-opaque Sexp_Atom type? It is not clear why do you need such a type. What are the properties of, and what is it for, given the application need to convert it anyway? As for raw memory addresses, it is possible to reinterpret them to any desired type in Ada, as you would do it in C, provided you know what are you doing. For this you can use so-called address-to-access conversion (see RM 13.7.2) or placement attribute 'Address (see 13.3(11)). > How to read Sexp_Atom objects from a file? See stream I/O attributes of types (RM 13.13.2). Otherwise, standard design patterns apply too. In any case you have to know the object's type in order to write/read it. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de