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=ham 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!postnews.google.com!z28g2000yqh.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: S-expression I/O in Ada Date: Thu, 12 Aug 2010 03:55:25 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8f4b65ed-e003-4ed9-8118-da8d240dd8aa@z28g2000yqh.googlegroups.com> References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <87aap6wcdx.fsf@ludovic-brenta.org> <87vd7jliyi.fsf@ludovic-brenta.org> <699464f5-7f04-4ced-bc09-6ffc42c5322a@w30g2000yqw.googlegroups.com> <87ocdbl41u.fsf@ludovic-brenta.org> <318d4041-eb01-4419-ae68-e6f3436c5b66@i31g2000yqm.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1281610525 3481 127.0.0.1 (12 Aug 2010 10:55:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Aug 2010 10:55:25 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z28g2000yqh.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13168 Date: 2010-08-12T03:55:25-07:00 List-Id: Natacha Kerensikova wrote on comp.lang.ada: [...] > Sexp_Stream is supposed to perform S-expression I/O over streams, > without ever constructing a S-expression into memory. It is supposed > to do only the encoding and decoding of S-expression format, to expose > its clients only atoms and relations. But how can it expose atoms and relations without an in-memory tree representation? Honestly, I do not think that such a concept is viable. Hence, the "S-Expression stream" must actually depend on the in-memory tree representation, both for reading and for writing. That is whay my package does. > A further unnamed yet package would handle the memory representation > of S-expressions, which involve object creation, memory management and > things like that. It would be a client of Sexp_Stream for I/O, so the > parsing would only be done at one place (namely Sexp_Stream). As I > said Ludovic Brenta's code might take this place. No, it replaces both of your hypothetical packages and I don't think you can have the "stream" package without the "S-Expression" package. You could, however, have an S-Expression package without any I/O. > There are situations when a memory representation of S-expressions is > not needed, and the tcp-connect example here seems to be such a case. > That's why I imagined TCP_Info as a client of Sexp_Stream instead of a > client of the second package. If no S-Expressions are needed in memory, then your entire data is just one big unstructured String, and you cannot parse it into a TCP_Info record unless you re-introduce the S-Expression tree in memory. >> I think the client should just do >> >> S : S_Expression := Some_Initialization; >> >> Put (File => F, Expression => S); > > To achieve such an interface, the client has to build an in-memory S- > expression object. In the tcp-connect example, there are eight nodes > (five atoms and three lists). They have to be somehow built, and it > doesn't look like a simple initialization. > > The second interface I proposed, with a lot of nested calls, builds > the S-expression object with functions looking like: > function NewList(Contents, Next: S_node_access) return S_node_access; > function AtomFromWhatever(Contents: whatever, Next: S_node_access) > return S_node_access; That's what I do in the test.adb example (using Cons () and To_Atom () respectively). > However, unless I'm building other higher-level functions, to build 8 > nodes I need 8 function calls, exactly like the second example. > > That 8-function-call example looks very C-ish to me, and honestly I > don't like it, I prefer the sequence of procedure calls from > Sexp_Stream example, but that's just a personal taste. > > The problem is that I don't see how to do it otherwise. Any idea would > be welcome. Here is one idea: embed the S-Expression "language" in Ada: function To_Sexp (S : in String) return S_Expression.T is String_Stream : constant Ada.Streams.Stream_IO.Stream_Access := Stream_Reading_From (S); -- implementation left as an exercise :) begin return Result : S_Expression.T do S_Expression.T'Read (String_Stream, Result); end return; end To_Sexp; TCP_Info : constant String := "(tcp-connect (host foo.bar) (port 80))"; TCP_Info_Structured := constant To_TCP_Info (To_Sexp (TCP_Info)); (this is based on my implementation). >> Your TCP_Info-handling pkg would convert the record into an S-expression, and >> call a single operation from your S-expression pkg to output the S-expression. > > That's the tricky part. At least so tricky that I can't imagine how to > do it properly. Yes, the S_Expression.Read operation is quite involved. But it can be done, and has been done :) -- Ludovic Brenta.