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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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!postnews.google.com!n19g2000prf.googlegroups.com!not-for-mail From: Natacha Kerensikova Newsgroups: comp.lang.ada Subject: Re: S-expression I/O in Ada Date: Sun, 1 Aug 2010 13:06:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <984db477-973c-4a66-9bf6-e5348c9b95f2@n19g2000prf.googlegroups.com> 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> NNTP-Posting-Host: 79.82.39.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1280693170 4995 127.0.0.1 (1 Aug 2010 20:06:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 1 Aug 2010 20:06:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n19g2000prf.googlegroups.com; posting-host=79.82.39.29; posting-account=aMKgaAoAAAAoW4eaAiNFNP4PjiOifrN6 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.2.3) Gecko/20100524 Firefox/3.6.3,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12788 Date: 2010-08-01T13:06:10-07:00 List-Id: On Aug 1, 8:49=A0pm, "Dmitry A. Kazakov" wrote: > On Sun, 1 Aug 2010 10:35:17 -0700 (PDT), Natacha Kerensikova wrote: > > On Aug 1, 2:53=A0pm, "Dmitry A. Kazakov" > > wrote: > >> How can it make sense if the type is unknown? If the type is known, wh= y 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 :-) I'm referring to this almost-RFC: http://people.csail.mit.edu/rivest/Sexp.t= xt > I mean, more natural would be "procedural": > > =A0 =A0tcp-connect (host (foo.example), port (80)) > > or > > =A0 =A0tcp-connect (foo.example, 80) Those are also perfectly valid ways of serializing the same information, but they are simply not S-expressions. I use S-expression as a sort of universal text-based container, just like most people use XML these days, except S-expressions can easily embed binary data and they are greatly simpler (as I said, ~1000 lines of commented 80-column C code with a few reinvented wheels embedded). > > This means that as far as the S-expression library is concerned, the by= te > > 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 abo= ve > 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 mu= st > be somewhere. In your example it could be: > > =A0 =A0type Connect is new Abstract_Node with record > =A0 =A0 =A0 =A0Host : IP_Address; > =A0 =A0 =A0 =A0Port : Port_Type; > =A0 =A0end record; It is indeed somewhere, but beyond the reach of a S-expression library: its belongs to the application using the library. The record you show here can't be part of a generic S-expression handling library. In my example, as far as the S-expression library is concerned, it looks like: "( ( ) ( ))" 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. 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 thought this was the strong type safety to prevent (de)serialization > > procedure from trying to interpret just any chunk of memory. > > No, actually it eases serialization because you can define > Serialize/Unserialize operations on the type. I honestly don't understand what you mean here. Am I misusing the word "serialization" to describe the process of converting an object from an internal representation (e.g. an integer) to a byte sequence (e.g. the ASCII string of its decimal representation, or the byte sequence in memory, both of them being two acceptable but different serializations, corresponding to different trade-offs (portability and readability vs space and time efficiency))? Thanks for making me think, Natacha