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,WEIRD_PORT 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!w30g2000yqw.googlegroups.com!not-for-mail From: Natacha Kerensikova Newsgroups: comp.lang.ada Subject: Re: S-expression I/O in Ada Date: Mon, 9 Aug 2010 12:59:37 -0700 (PDT) Organization: http://groups.google.com Message-ID: <699464f5-7f04-4ced-bc09-6ffc42c5322a@w30g2000yqw.googlegroups.com> References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <87aap6wcdx.fsf@ludovic-brenta.org> <87vd7jliyi.fsf@ludovic-brenta.org> NNTP-Posting-Host: 95.152.65.220 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1281383977 29621 127.0.0.1 (9 Aug 2010 19:59:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 9 Aug 2010 19:59:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w30g2000yqw.googlegroups.com; posting-host=95.152.65.220; 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:13016 Date: 2010-08-09T12:59:37-07:00 List-Id: On Aug 9, 8:49=A0pm, Ludovic Brenta wrote: > I pursued that idea a little further and actually wrote an embryonic > S-Expression library. =A0I'm not entirely satisfied with it because it > uses copy semantics instead of reference semantics and so is probably > inefficient. =A0But it does demonstrate how to read and write > S-Expressions on a stream (e.g. a file). =A0Also, it shows how to > hex-encode and hex-decode blobs, which I've modelled as Storage_Arrays. > > You can browse the sources here: > > http://green.ada-france.org:8081/branch/changes/org.ludovic-brenta.s_... > > Enjoy. =A0(the license is the GPLv3 or later). Interesting, though it seems your code won't like strings containing a double-quote. However, the principal conclusion I draw from reading this is that I'm still far from having the Ada level required to write anything like that (since I can't even understand everything while reading it). Still, from what I understood, I'm not fond of the idea of having to write type-to-atom conversion procedure while they already exist. It occurred to me that most types already know how to serialize themselves, through the Stream subsystem. Strings, Unbounded_strings, Integers, Float, etc, can all be read from and written into a stream. So the code to convert them into file-suitable Stream_Element_Array exist. Won't be a pity not to reuse it? Pursuing this idea leads to a library quite different from what I had in mind when I started this thread. Let's call it Sexp_Stream, which would be derived from Root_Stream_Type. Then Read and Write procedure are called (from what I understand) by type'Read and type'Write after said type has turned itself into a Stream_Element_Array. That would cover atom I/O, and some procedures must be added to cover the list I/ O part. I think I can imagine how the writing part would happen: after having initialized a Sexp_Stream object with various information, including an underlying stream where the S-expression would be actually written, the application would use the Write procedure to append an object as an atom to the current node, and the newly appended atom would become the current node. List procedure would be called something like List_Open, to open a new list and append following nodes into it, and List_Close, to close the current list and come back to the previous list. Using my tcp-connect example, it would look like this (please excuse Ada syntax error and focus on the idea): Sexp_Stream.Open(SxStream, underlying_stream, ...); Sexp_Stream.Open_List(SxStream); String'Write(SxStream, "tcp-connect"); Sexp_Stream.Open_List(SxStream); String'Write(SxStream, "host"); String'Write(SxStream, Hostname); Sexp_Stream.Close_List(SxStream); Sexp_Strean.Open_List(SxStream); String'Write(SxStream, "port"); Integer'Write(SxStream, PortNumber); Sexp_Stream.Close_List(SxStream); Sexp_Stream.Close_List(SxStream); Now I have to admit I don't know how to specify the reading part of such a Sexp_Stream. I guess I would need the notion of a current node, with a function telling the application whether the current node is a list or an atom, type'Read converting the current atom into said type (and raising an exception when the current atom is a list), and some procedures to get to the next node, to the frist node following the current list (i.e. up one level), and when the current node is a list to go the first node of the list (i.e. one level deeper). However such a library wouldn't cover all my S-expression needs, because I sometimes need to keep S-expressions into memory, so there would be another package for in-memory S-expressions, which would have to interact nicely with Sexp_Stream. So, how does it sound? Is it totally crazy? Is it totally not-Ada? Is there something right in there? For Jeffry Carter (and anybody interested in helping me understand the Ada way): here is how it looks like when I haven't thought much about it. Notice that all this is completely from the point of view of the application using the package, with very few implementation choices. If I knew Ada, wouldn't these explanations be pretty much the contents of the specification file, with about everything from the body being still to invent? How Ada-ish is that thought process? Thanks in advance for your reviews of my ideas, Natacha