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 Path: g2news1.google.com!news4.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool2.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="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <1qk2k63kzh7yv$.3jgc403xcqdw$.dlg@40tude.net> <8ae8e899-9eef-4c8c-982e-bfdfc10072f1@h17g2000pri.googlegroups.com> <258zlxrv4fn6.1vszho1rtmf48$.dlg@40tude.net> <984db477-973c-4a66-9bf6-e5348c9b95f2@n19g2000prf.googlegroups.com> Date: Sun, 1 Aug 2010 23:13:26 +0200 Message-ID: NNTP-Posting-Date: 01 Aug 2010 23:13:26 CEST NNTP-Posting-Host: 83e4a70a.newsspool4.arcor-online.net X-Trace: DXC=AZZ[:RQ4IUKQ8L?[0[KbXjU X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:12792 Date: 2010-08-01T23:13:26+02:00 List-Id: On Sun, 1 Aug 2010 13:06:10 -0700 (PDT), Natacha Kerensikova wrote: > On Aug 1, 8:49�pm, "Dmitry A. Kazakov" > wrote: >> On Sun, 1 Aug 2010 10:35:17 -0700 (PDT), Natacha Kerensikova wrote: >>> On Aug 1, 2:53�pm, "Dmitry A. Kazakov" >>> wrote: >>>> How can it make sense if the type is unknown? If the type is known, why not >>>> to state it? >> >>> Actually the type is deduced from the context, e.g. >>> (tcp-connect (host foo.example) (port 80)) >> >> Hmm, why do you consider brackets as separate elements? > > Because that's the definition of S-expressions :-) OK, why S-expressions, then? (:-)) > I'm referring to this almost-RFC: http://people.csail.mit.edu/rivest/Sexp.txt I see, yet another poor data format. > I use S-expression as a sort of universal text-based container, just > like most people use XML these days, These wonder me too. I see no need in text-based containers for binary data. Binary data aren't supposed to be read by people, they read texts. And conversely the machine shall not read texts, it has no idea of good literature... >>> This means that as far as the S-expression library is concerned, the byte >>> sequence read from the file is not typed. Its typing actually has to be >>> delayed until the application has enough context to interpret it. Hence >>> the need of a typeless chunk of data. >> >> The above is mere syntax, it is not clear why internal/external >> representation must be as you described. (Actually, the structures as above >> are widely used in compiler construction e.g. syntax tree, Reverse Polish >> notation etc.) >> >> There is no such thing as untyped data. The information about the type must >> be somewhere. In your example it could be: >> >> � �type Connect is new Abstract_Node with record >> � � � �Host : IP_Address; >> � � � �Port : Port_Type; >> � �end record; > > It is indeed somewhere, but beyond the reach of a S-expression > library: its belongs to the application using the library. Yes > The record > you show here can't be part of a generic S-expression handling > library. It need not to be. Abstract_Node should declare Serialize and Unserialize operations, which Connect does implement. The library makes dispatching calls. Of course you can declare something like: � type List_Of_Anything is new Abstract_Node with -- Container of class-wide objects and implement its Serialize and Unserialize through walking the items of an calling its Serialize and Unserialize. BTW, this is how attributes 'Input and 'Output work with arrays. > In my example, as far as the S-expression library is concerned, it > looks like: > "( ( ) ( > ))" That is no matter. Serialize/Unserialize will use this format if they have to. > The library is not supposed to care about what those some_stuff_ are. > Actually, the library is suppose to get binary data from the > application along with the tree structure described above, store it > into a sequence of bytes (on a disk or over a network or whatever), > and to retrieve from the byte sequence the original tree structure > along with the binary data provided. Serialize can yield a binary chunk, but if you have to write it anyway, why not to write text? You insisted on having text, why do mess with binary stuff? > But now that I think about it, I'm wondering whether I'm stuck in my C > way of thinking and trying to apply it to Ada. Am I missing an Ada way > of storing structured data in a text-based way? I think yes. Though it is not Ada-specific, rather commonly used OOP design patterns. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de