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-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Natasha Kerensikova Newsgroups: comp.lang.ada Subject: Re: S-expression I/O in Ada Date: Thu, 19 Aug 2010 08:09:04 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Thu, 19 Aug 2010 08:09:04 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="Mda950WjNwNLAFOE7yJXQw"; logging-data="11813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182W4vAYf1PkIgqpfCUhe8L" User-Agent: slrn/0.9.9p1 (FreeBSD) Cancel-Lock: sha1:oU8qXTVW0bpTPqdzPBOCQAXQr3g= Xref: g2news1.google.com comp.lang.ada:13507 Date: 2010-08-19T08:09:04+00:00 List-Id: On 2010-08-18, Jeffrey Carter wrote: > On 08/18/2010 03:49 AM, Natasha Kerensikova wrote: >> >> I have indeed forgotten about Ada containers. However after having read >> A.18.2 and A.18.3, it seems to me that Doubly_Linked_Lists are more >> appropriate than vectors: the recursive structure of S-expressions can >> make assignment (i.e. deep copies) quite expensive, and >> Doubly_Linked_Lists seem designed primarily to avoid copy of contained >> objects (though I may be mistaken). Usual operations on S-expressions >> are append and traversal, on which Vectors don't provide a significant >> improvement (unlike e.g. random access). >> >> Does it make sense or am I missing something? > > You're mistaken about Doubly_Linked_Lists not doing a deep copy; on the other > hand, adding an element to a Vector may cause reallocation with an internal > copy, which lists avoid. Actually I was mixing things up (at least twice). When I wrote the paragraph above my concern was both reallocation *and* deep copy. More precisely I thought the reallocation, triggered e.g. by Vectors.Append, would not only cause the internal array to be copied, but all items in the Vector to be deep-copied from the old array to the newly allocated array. Then I thought I was mistaken, and just like C's realloc() doesn't mess with internal pointers pointing to outside of the reallocated area, the Vector could do a mere shallow copy. And now I have just had a look at GNAT FSF (v4.4) implementation, and there is a normal array assignment, which I guess triggers an assignment of each item, which in our case (record containing a Vector) triggers a deep copy. Or am I wrong here? So it seems a simple Vector.Append call might trigger a copy of the entire S-expression, which makes a strong point for the linked-list, doesn't it? > I used Vector here because I thought it would be clearer what is > happening, since it's an unbounded array. Iteration thus uses "for" > loops and indexing to access the elements, similar to arrays; I > thought this would be clearer to a beginner (in Ada). Lists and arrays > are both sequences and do the same things, so either could be used. Ok, I understand the motive. And indeed, your implementation was the first I understood almost completely, but I can't tell how much is due to your clarity intend and how much is due to having already tried to write one. Anyway, thanks for your efforts in pedagogy. > OK, I misunderstood that bit. Making the definition of Atom public would be > fine, then, allowing clients to create their own. You could also replace the > definition of Atom with > > subtype Atom is Byte_Lists.Vector; > > which would simplify the implementation a bit. I'm still wondering which is better between vector and array. I thought a vector could be easily be turned into an array, hence my initial choice of arrays, but it seems there is no such vector primitive in A.18.2. Another tough choice... > Yes, ideally we want a list of S_Expression. However, the language > doesn't allow us to create that directly. I can't instantiate Vectors > with S_Expression before I declare S_Expression, and I can't declare > S_Expression until I've instantiated Vectors for lists. OK, I understand the catch-22 problem here. I guess it will be the same with linked lists instead of vectors. Is there any other (perhaps more difficult for a beginner) way to address that issue? Thanks a lot for your help, Natacha