comp.lang.ada
 help / color / mirror / Atom feed
From: Natacha Kerensikova <lithiumcat@gmail.com>
Subject: Re: S-expression I/O in Ada
Date: Tue, 10 Aug 2010 05:06:29 -0700 (PDT)
Date: 2010-08-10T05:06:29-07:00	[thread overview]
Message-ID: <5d1d705a-008a-43f1-aa19-9b4878ec926b@m1g2000yqo.googlegroups.com> (raw)
In-Reply-To: 16xmnn0qe5yog.ii1p0ap9yuth$.dlg@40tude.net

On Aug 10, 12:36 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Tue, 10 Aug 2010 01:56:22 -0700 (PDT), Natacha Kerensikova wrote:
> > On Aug 9, 12:56 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> >> I thought you wanted to represent *objects* ... as S-sequences?
>
> > It depends what you call object. Here again, my vocabulary might has
> > been tainted by C Standard. Take for example a record, I would call
> > each component an object, as well as the whole record itself.
>
> That's OK. Using this definition S-sequence in the memory is an object.

Just to be sure, what is it exactly you call S-sequence? For the rest
of this post I will assume it synonym of S-expression atom, I hope my
answers won't be too misguided.

> Which was the question: what was wrong with the first object so that you
> wanted another instead?

The first object is the internal memory representation designed for
actual efficient use. For example, an integer will probably be
represented by its binary value with machine-defined endianness and
machine-defined size.

The other object is a "serialized" representation, in the sense that
it's designed for communication and storage, for example the same
integer, in a context where it will be sent over a network, can be for
example represented as an ASCII-encoded decimal number, or in binary
but with a predefined size and endianness. This is really the same
considerations as when storing or sending an object directly, except
that is has to reside in memory for a short time. There is no more
conversions or representations than when S-expression-lessly storing
or sending objects; the only difference is the memory buffering to
allow S-expression-specific information to be inserted around the
stream.

> My first take was S-sequence used as an object presentation outside the
> memory, because you used the word "format". Now it looks as a solution
> before the problem. You seem going to convert objects to S-sequences *in*
> the memory and then dump the result them into files. Is it so?

Yes, it is.

> What was the problem then?

The problem is to organize different objects inside a single file. S-
expression standardize the organization and relations between objects,
while something else has to be done beyond S-expression to turn
objects into representations suitable to live in a file.

Or the same thing with, instead of a file, an IPC socket or a network
socket or whatever, I just don't know how to call it generically
without resorting to a word derived from "serialize", but I hope you
get the point anyway.

> Because it cannot work without a conversion between
> S-sequence in the memory (object) and S-sequence in the file
> (representation).

The S-expression standard describe what conversions are allowed and in
what they consist. I cannot follow the standard without such a
conversion anyway, so either I do it or I drop the idea of S-
expressions, but then I don't have anything to portably store or
transmit  objects, so back to square one.

> Why do you need S-sequence in the memory, while dumping
> objects directly into files as S-sequences (if you insist on having them)
> is simpler, cleaner, thinner, faster.

Because I need to examine the S-sequence before writing it to disk, in
order to have enough information to write S-expression metadata. At
the very lest, I need to know the total size of the atom before
allowing its first byte to be send into the file.

> >> Note that Stream_Element is machine-depended as well.
>
> > I'm sadly aware of that. I need an octet-sequence to follow the S-
> > expression standard, and there is here an implementation trade-off:
> > assuming objects already know how to serialize themselves into a
> > Stream_Element_Array, I can either code a converter from
> > Stream_Element_Array to octet-sequence, or reinvent the wheel and code
> > a converter for each type directly into an octet-sequence. For some
> > strange reason I prefer by far the first possibility.
>
> That depends on your goal. Streams are machine-dependent. Streams of octets
> are not. If you want to exchange objects in the form of S-sequences across
> the network you have to drop standard stream implementations of the objects
> and replace them with your own, based on the stream octets.

This looks like a very strong point in favor of using an array-of-
octets to represent S-expression atoms.

> In this case
> you will not use Stream_Element_Array directly. You will read and write
> octets, by Octet'Read and Octet'Write. Provided that octet streams work,
> which is about 99.9%, I guess. When they are not capable to handle octets
> properly, you will have to implement I/O manually. If you wrap Octet'Read
> into a function, you will be able to exchange the I/O layer without
> affecting the upper ones. If we look at all this mechanics we will see the
> old good OSI model.

That sounds like a very nice way of doing it. So in the most common
case, there will still be a stream, provided by the platform-specific
socket facilities, which will accept an array-of-octets, and said
array would have to be created from objects by custom code, right?
(just want to be sure I understood correctly).

> In other post Jeffrey Carter described this as low-level. Why not to tell
> the object: store yourself and all relations you need, I just don't care
> which and how?

That's indeed a higher-level question. That's how it will happen at
some point in my code; however at some other point I will still have
to actually implement said object storage, and that's when I will
really care about which and how. I'm aware from the very beginning
that a S-expression library is low-level and is only used by mid-level
objects before reaching the application.

I've discussed with a friend of mine who has a better knowledge than
me about what actually is a parser and a lexer and things like that.
It happens that what my S-expression code is intended to be is
actually a partial parser, requiring some more specific stuff on top
on it to actually be called a parser. Just like S-expression is a
partial format in that it describes how to serialize relations between
atoms without describing how objects are serialized into atoms.

At some point in my projects I will have to write various
configuration file parsers, template parsers, and maybe a lot of other
parsers. They can all be treated as independent parsers, and
implemented with independent code, maybe derived from YACC or
something. I didn't choose that path, I chose rather to use what I
called a S-expression library, which is sort of a common core to all
these parsers, so I only have left to write the specific part of each
situations, which is matching the keywords and typing/deserializing
the objects.

> > But there are still situations where S-expression have to be stored in
> > memory.
>
> There is no such cases!

Right, I guess just like goto-use, they can always be avoided, but I'm
still not convinced it's always the best.

> > For examples the templates, where S-expressions represent a
> > kind of limited programming language that is re-interpreted for each
> > template extension.
>
> I am not sure what do you mean here, but in general template is not the
> object, its instance is.

Just to be sure we use the same words, I'm talking here about HTML
templates. The basic definition of a S-expression is a list of nodes,
each of which can be a list or an atom; for a template I copy directly
atom contents into the output, and lists are interpreted as functions,
with an "instance" (or whatever is called the thing containing data to
populate the template) handling the actual "execution" of the
function. Now the interest I find in the recursive definition of S-
expression is that it's easy to pass template-fragments as arguments
of these functions. For this it's much easier to let the S-expression
describing the template reside into memory. S-expressions are of
course not required here, but provide a nice and simple unified
format.

> You do not need S-expressions here either. You can
> store/restore templates as S-sequences. A template in the memory would be
> an object with some operations like Instantiate_With_Parameters etc. The
> result of instantiation will be again an object and no S-sequence.

Well how would solve the problem described above without S-
expressions? (That's a real question, if something simpler and/or more
efficient than my way of doing it exists, I'm genuinely interested.)

> > the latter being
> > roughly the low-level (as in "close to the hardware", at least close
> > enough not to rule out programming for embedded platforms and system
> > programming) and the performance.
>
> (BTW, Ada is closer to the hardware than C is. You can even describe
> interrupt handlers in Ada. Try it in C.)

Fantastic \o/

> > Now I can't explain why your posts often make me feel Ada is
> > completely out of my tastes in programming languages,
>
> In the way of programming you mean? I wanted to convey that a
> "C-programmer" will have to change some habits when switching to Ada.

I unsure about you mean here by "C-programmer". As I said in other
posts, I don't really code the same way as other C coders I've met. I
still don't know whether it's a good thing or not. I'm willing to
change some of my habits to switch to Ada, while I won't give up some
other even if mean giving up Ada. The main criterion being that coding
must remain fun, because it makes no sense to continue doing a leisure
activity that isn't fun anymore.

> But a stubborn hardcore "C-programmer" might become very frustrated
> very soon. A competent C developer will only enjoy Ada.

I somehow hope I'm more of the latter than the former.

BTW, that post of yours is one that encourages me rather than restrain
me.


Thanks for your interesting replies,
Natacha



  reply	other threads:[~2010-08-10 12:06 UTC|newest]

Thread overview: 252+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-01 12:17 S-expression I/O in Ada Natacha Kerensikova
2010-08-01 12:53 ` Dmitry A. Kazakov
2010-08-01 17:35   ` Natacha Kerensikova
2010-08-01 18:49     ` Dmitry A. Kazakov
2010-08-01 20:06       ` Natacha Kerensikova
2010-08-01 21:13         ` Dmitry A. Kazakov
2010-08-02  7:17           ` Georg Bauhaus
2010-08-02  7:58             ` Dmitry A. Kazakov
2010-08-07  7:23           ` Natacha Kerensikova
2010-08-07  8:39             ` Dmitry A. Kazakov
2010-08-07 12:56               ` Natacha Kerensikova
2010-08-07 14:23                 ` Dmitry A. Kazakov
2010-08-08 12:23                   ` Natacha Kerensikova
2010-08-08 13:01                     ` Dmitry A. Kazakov
2010-08-08 13:49                       ` Natacha Kerensikova
2010-08-08 15:15                         ` Dmitry A. Kazakov
2010-08-09  9:55                           ` Natacha Kerensikova
2010-08-09 10:56                             ` Dmitry A. Kazakov
2010-08-10  8:56                               ` Natacha Kerensikova
2010-08-10 10:17                                 ` Georg Bauhaus
2010-08-10 10:36                                 ` Dmitry A. Kazakov
2010-08-10 12:06                                   ` Natacha Kerensikova [this message]
2010-08-10 15:46                                     ` Dmitry A. Kazakov
2010-08-10 21:22                                       ` Simon Wright
2010-08-11  7:37                                         ` Dmitry A. Kazakov
2010-08-11 17:32                                           ` Simon Wright
2010-08-11 17:53                                             ` Dmitry A. Kazakov
2010-08-11  9:43                                       ` Natacha Kerensikova
2010-08-11 10:37                                         ` Dmitry A. Kazakov
2010-08-11 11:38                                           ` Natacha Kerensikova
2010-08-11 12:58                                             ` Robert A Duff
2010-08-11 15:30                                               ` Natacha Kerensikova
2010-08-11 23:39                                                 ` Randy Brukardt
2010-08-12  1:31                                                   ` Robert A Duff
2010-08-12  8:53                                                   ` Natacha Porté
2010-08-12  9:22                                                     ` Georg Bauhaus
2010-08-13  9:43                                                       ` Natacha Kerensikova
2010-08-10 21:56                                 ` Randy Brukardt
2010-08-09 15:40                             ` Simon Wright
2010-08-09 16:35                               ` Robert A Duff
2010-08-10  0:51                                 ` Randy Brukardt
2010-08-10  1:00                                   ` Jeffrey Carter
2010-08-10 21:36                                     ` Randy Brukardt
2010-08-10 22:24                                       ` Jeffrey Carter
2010-08-10 12:50                                   ` Robert A Duff
2010-08-10 22:06                                     ` Randy Brukardt
2010-08-09 18:37                               ` Natacha Kerensikova
2010-08-09 19:10                                 ` Robert A Duff
2010-08-08 14:08                     ` Duke Normandin
2010-08-08 15:34                     ` Robert A Duff
2010-08-08 18:24                       ` Dmitry A. Kazakov
2010-08-08 20:03                         ` Robert A Duff
2010-08-08 20:39                           ` Dmitry A. Kazakov
2010-08-08 21:08                             ` Robert A Duff
2010-08-09  6:50                               ` Dmitry A. Kazakov
2010-08-09 13:48                                 ` Robert A Duff
2010-08-09 14:38                                   ` Dmitry A. Kazakov
2010-08-09 15:14                                     ` Georg Bauhaus
2010-08-09 16:11                                       ` Dmitry A. Kazakov
2010-08-09 16:46                                         ` Georg Bauhaus
2010-08-09 17:05                                           ` Robert A Duff
2010-08-09 18:29                                             ` Georg Bauhaus
2010-08-09 19:18                                               ` Robert A Duff
2010-08-10  8:21                                                 ` Georg Bauhaus
2010-08-09 20:40                                           ` Dmitry A. Kazakov
2010-08-09 22:21                                             ` Georg Bauhaus
2010-08-10  7:07                                               ` Dmitry A. Kazakov
2010-08-09 16:47                                         ` Robert A Duff
2010-08-09 19:59                                           ` Dmitry A. Kazakov
2010-08-09 21:34                                             ` Robert A Duff
2010-08-09 22:29                                               ` Jeffrey Carter
2010-08-10  7:48                                               ` Dmitry A. Kazakov
2010-08-09 21:54                                             ` _FrnchFrgg_
2010-08-09 22:32                                               ` Georg Bauhaus
2010-08-10  7:16                                               ` Dmitry A. Kazakov
2010-08-10 11:06                                                 ` _FrnchFrgg_
2010-08-10 11:19                                                   ` Dmitry A. Kazakov
2010-08-10 23:04                                                     ` _FrnchFrgg_
2010-08-11 14:10                                                       ` Dmitry A. Kazakov
2010-08-11 17:51                                                         ` Structural unification (pattern matching) in Ada [was: Re: S-expression I/O in Ada] _FrnchFrgg_
2010-08-11 18:06                                                           ` Dmitry A. Kazakov
2010-08-11 19:43                                                           ` Robert A Duff
2010-08-11 20:26                                                             ` (see below)
2010-08-11 21:21                                                               ` Structural unification (pattern matching) in Ada Simon Wright
2010-08-12 12:43                                                             ` Structural unification (pattern matching) in Ada [was: Re: S-expression I/O in Ada] _FrnchFrgg_
2010-08-10  1:06                                             ` S-expression I/O in Ada Randy Brukardt
2010-08-09 16:50                                       ` Robert A Duff
2010-08-09 18:32                                       ` Natacha Kerensikova
2010-08-09 19:06                                         ` Jeffrey Carter
2010-08-09 19:24                                           ` Robert A Duff
2010-08-09 19:35                                         ` (see below)
2010-08-09 17:00                                     ` Robert A Duff
2010-08-09 20:27                                       ` Dmitry A. Kazakov
2010-08-09 21:30                                         ` Robert A Duff
2010-08-10  1:17                                         ` Randy Brukardt
2010-08-10  6:48                                           ` Dmitry A. Kazakov
2010-08-10 21:42                                             ` Randy Brukardt
2010-08-11  8:02                                               ` Dmitry A. Kazakov
2010-08-11 23:18                                                 ` Randy Brukardt
2010-08-12  6:20                                                   ` Dmitry A. Kazakov
2010-08-12 20:56                                                     ` Randy Brukardt
2010-08-13  6:56                                                       ` Dmitry A. Kazakov
2010-08-14  0:52                                                         ` Randy Brukardt
2010-08-09 18:55                                   ` Jeffrey Carter
2010-08-09 18:20                               ` Natacha Kerensikova
2010-08-09 19:19                                 ` Robert A Duff
2010-08-07 15:38             ` Jeffrey Carter
2010-08-07 17:01               ` Natacha Kerensikova
2010-08-08  6:52                 ` Jeffrey Carter
2010-08-08 13:11                   ` Natacha Kerensikova
2010-08-08 15:24                     ` Robert A Duff
2010-08-09 18:00                       ` Natacha Kerensikova
2010-08-09 18:09                         ` Robert A Duff
2010-08-08 20:34                     ` Jeffrey Carter
2010-08-09 18:10                       ` Natacha Kerensikova
2010-08-08 10:26                 ` Simon Wright
2010-08-08 11:44                   ` Dmitry A. Kazakov
2010-08-08 11:48                     ` Dmitry A. Kazakov
2010-08-08 14:05                   ` Natacha Kerensikova
2010-08-08 20:11                   ` Jeffrey Carter
2010-08-14  1:02             ` Yannick Duchêne (Hibou57)
2010-08-14  9:53               ` Georg Bauhaus
2010-08-14 11:32               ` Natacha Kerensikova
2010-08-01 22:03     ` Simon Wright
2010-08-02 17:08       ` Pascal Obry
2010-08-02 19:08         ` Simon Wright
2010-08-01 16:01 ` Ludovic Brenta
2010-08-09 18:49   ` Ludovic Brenta
2010-08-09 19:59     ` Natacha Kerensikova
2010-08-10  0:11       ` Ludovic Brenta
2010-08-10  0:57         ` Jeffrey Carter
2010-08-10  6:47           ` Natacha Kerensikova
2010-08-10 18:13             ` Jeffrey Carter
2010-08-12  9:26               ` Natacha Kerensikova
2010-08-12 10:55                 ` Ludovic Brenta
2010-08-12 12:16                   ` Natacha Kerensikova
2010-08-12 12:46                     ` Ludovic Brenta
2010-08-12 13:23                       ` Natacha Kerensikova
2010-08-12 16:19                         ` Ludovic Brenta
2010-08-12 17:17                           ` Natacha Kerensikova
2010-08-12 18:51                 ` Jeffrey Carter
2010-08-13  9:32                   ` Natacha Kerensikova
2010-08-13 15:52                     ` Ludovic Brenta
2010-08-13 22:53                     ` Jeffrey R. Carter
2010-08-14 11:10                       ` Natacha Kerensikova
2010-08-10 15:48       ` Ludovic Brenta
2010-08-10 15:59         ` Georg Bauhaus
2010-08-12  7:53           ` Ludovic Brenta
2010-08-12 18:55             ` Jeffrey Carter
2010-08-12 19:59               ` Ludovic Brenta
2010-08-12 20:23                 ` Natacha Kerensikova
2010-08-12 20:45                   ` Ludovic Brenta
2010-08-13  8:24                     ` Natacha Kerensikova
2010-08-13  9:08                       ` Ludovic Brenta
2010-08-14 10:27                         ` Natacha Kerensikova
2010-08-14 11:11                           ` Ludovic Brenta
2010-08-14 12:17                             ` Natasha Kerensikova
2010-08-14 13:13                               ` Ludovic Brenta
2010-08-14 13:33                                 ` Yannick Duchêne (Hibou57)
2010-08-12 22:25                 ` Jeffrey R. Carter
2010-08-13  9:10                   ` Natacha Kerensikova
2010-08-13  9:51                     ` Dmitry A. Kazakov
2010-08-14 10:36                       ` Natacha Kerensikova
2010-08-14 10:57                         ` Dmitry A. Kazakov
2010-08-13 19:23                     ` Jeffrey Carter
2010-08-13 19:42                       ` Dmitry A. Kazakov
2010-08-13 20:44                       ` Yannick Duchêne (Hibou57)
2010-08-14  0:57                       ` Randy Brukardt
2010-08-14 10:47                       ` Natacha Kerensikova
2010-08-13 19:36                     ` Simon Wright
2010-08-12 20:11               ` Natacha Kerensikova
2010-08-12 20:22             ` Ludovic Brenta
2010-08-01 18:25 ` Jeffrey Carter
2010-08-01 19:43   ` Natacha Kerensikova
2010-08-01 19:53     ` Ludovic Brenta
2010-08-01 20:00       ` Dmitry A. Kazakov
2010-08-01 20:03     ` Jeffrey Carter
2010-08-01 20:34 ` Georg Bauhaus
2010-08-01 20:44   ` Georg Bauhaus
2010-08-01 21:01 ` anon
2010-08-12 23:26 ` Shark8
2010-08-13  2:31   ` Shark8
2010-08-13  8:56   ` Natacha Kerensikova
2010-08-13 10:30     ` Georg Bauhaus
2010-08-13 15:58     ` Shark8
2010-08-13 21:48     ` Shark8
2010-08-14 11:02       ` Natacha Kerensikova
2010-08-17 17:01 ` Natasha Kerensikova
2010-08-17 19:00   ` Jeffrey Carter
2010-08-18 10:49     ` Natasha Kerensikova
2010-08-18 11:14       ` Ludovic Brenta
2010-08-18 11:59         ` Natasha Kerensikova
2010-08-18 12:31           ` Ludovic Brenta
2010-08-18 13:16             ` J-P. Rosen
2010-08-18 13:55             ` Natasha Kerensikova
2010-08-18 14:40               ` J-P. Rosen
2010-08-20 20:50                 ` Yannick Duchêne (Hibou57)
2010-08-18 15:07               ` Ludovic Brenta
2010-08-19  7:42                 ` Natasha Kerensikova
2010-08-18 12:51           ` Georg Bauhaus
2010-08-18 13:24             ` Natasha Kerensikova
2010-08-18 14:40               ` Georg Bauhaus
2010-08-18 23:50           ` Randy Brukardt
2010-08-18 11:22       ` Georg Bauhaus
2010-08-18 12:02         ` Natasha Kerensikova
2010-08-20 21:04           ` Yannick Duchêne (Hibou57)
2010-08-22 10:21             ` Natasha Kerensikova
2010-08-22 10:28               ` Simon Wright
2010-08-22 17:13                 ` Jeffrey Carter
2010-08-22 14:06               ` Dmitry A. Kazakov
2010-08-21 19:36           ` Yannick Duchêne (Hibou57)
2010-08-18 18:08       ` Jeffrey Carter
2010-08-19  8:09         ` Natasha Kerensikova
2010-08-19 10:16           ` Natasha Kerensikova
2010-08-19 10:42             ` Dmitry A. Kazakov
2010-08-22 10:24               ` Natasha Kerensikova
2010-08-22 14:10                 ` Dmitry A. Kazakov
2010-08-19 18:07             ` Jeffrey Carter
2010-08-22 10:43               ` Natasha Kerensikova
2010-08-22 17:17                 ` Jeffrey Carter
2010-08-19 17:59           ` Jeffrey Carter
2010-08-22 10:45             ` Natasha Kerensikova
2010-08-22 17:20               ` Jeffrey Carter
2010-08-24 11:41       ` Natasha Kerensikova
2010-08-25  1:56         ` Jeffrey Carter
2010-08-25 12:18           ` Natasha Kerensikova
2010-08-25 14:07             ` Jeffrey Carter
2010-08-25  8:06         ` Georg Bauhaus
2010-08-25 13:27           ` Natasha Kerensikova
2010-08-25 18:55           ` Simon Wright
2010-08-25 19:19             ` Georg Bauhaus
2010-08-25 19:23               ` Georg Bauhaus
2010-08-25 22:38               ` Simon Wright
2010-08-25 23:55                 ` Georg Bauhaus
2010-08-27 13:19 ` Natasha Kerensikova
2010-08-27 14:57   ` Georg Bauhaus
2010-08-29 10:45     ` Natasha Kerensikova
2010-08-29 13:10       ` Simon Wright
2010-08-29 14:21         ` Natasha Kerensikova
2010-08-29 14:30           ` Niklas Holsti
2010-08-29 13:23       ` Robert A Duff
2010-08-29 13:57         ` Jeffrey Carter
2010-08-29 14:18         ` Britt Snodgrass
2010-08-29 14:29         ` Natasha Kerensikova
2010-08-29 15:12           ` Robert A Duff
2010-09-03 21:52             ` Randy Brukardt
2010-08-29 13:56       ` Jeffrey Carter
2010-08-29 14:34         ` Natasha Kerensikova
2010-08-29 14:55           ` Dmitry A. Kazakov
2010-08-29 15:25           ` Robert A Duff
2010-08-29 18:50       ` Georg Bauhaus
2010-08-29 21:43         ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox