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!5g2000yqz.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 09:19:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8e7cb956-6d25-46c2-a855-a48673b4ee5e@5g2000yqz.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> <8f4b65ed-e003-4ed9-8118-da8d240dd8aa@z28g2000yqh.googlegroups.com> <6a5068d7-b774-4c52-8b00-ddcc76865847@p7g2000yqa.googlegroups.com> <0cff56bc-32fc-44fe-9e29-9387a4eb4588@l14g2000yql.googlegroups.com> <7990e251-0a92-4790-a24e-0c1899e9295c@a36g2000yqc.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 1281629982 26526 127.0.0.1 (12 Aug 2010 16:19:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Aug 2010 16:19:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 5g2000yqz.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:13181 Date: 2010-08-12T09:19:42-07:00 List-Id: Natacha Kerensikova wrote on comp.lang.ada: >> The reason why I prefer to expose the S-Expression is because, in the >> general (arbitrarily complex) case, you cannot traverse an S- >> Expresssion linearly; you need to traverse it as what it really is, a >> tree. A stream suggests linear traversal only. > > Yes, linear traversal only is indeed a limitation of Sexp_Stream. > That's the reason why I had in mind another package of object and > memory handling, which would rely on Sexp_Stream for the parsing. > > I prefer (for now) the Sexp_Stream/memory-object split because 1. it > makes thing more modular, which means more possibilities of localized > changes and of implementation overhaul without changing specification, > and 2. in my real-life application the linear traversal is often > enough. Far from always though, especially when one counts cases when > application can traverse linearly but when of the subobjects needs to > store its sub-S-expression in memory. OK, let's assume this can work technically. Let's do a cost-benefit analysis of your preferred solution. Cost: you limit the use of the S-Expression parser to linear traversal only; this makes it unsuitable for a general-purpose library, which I thought was one of your goals. Cost: while the S-Expression parser has to construct S-Expressions in memory anyway, you need artificial measures to hide the tree structure from clients, thereby cluttering the implementation of the S- Expression parser and making any future changes more difficult. Benefit: in memory-constrained systems, you may deallocate memory soon (after the client calls Move_Up, e.g.) and allocate it late (only when the client calls Get_Atom or Move_Down), thereby holding only one node at a time in memory. But if you're planning to write a web server, I don't think you were concerned about the ~100 bytes necessary for the tree of "(tcp-connect (host foo.bar) (port 80))", were you? Benefit: I can't see any for the client, honestly, since parsing your stream is not easier than parsing the S-Expression tree directly, as you can see when comparing our respective implementations of TCP_Info.Read. So, I do think the more general solution is better. -- Ludovic Brenta.