← Back to team overview

kicad-developers team mailing list archive

Re: Forward-compatibility in s-expression formats

 

On Thu, May 08, 2014 at 03:14:05AM -0500, Dick Hollenbeck wrote:
> Not sure why you think the discussion pertains to the programming language.  python, Java,
> C++, C all have both SAX and DOM parsers for XML.  XML is a noisy s-expression basically.

With the restriction of having a non-structured first element. Other
than that, yes, there is an isomorphism.

> The discussion also does not involve garbage collection.  Don't know why that enters into
> it.  If the most useful data structure to your program is a struct or class consisting of
> integers, strings and floats, then having a tree that is pure text fields is not optimal.

It actually depends a lot on the underlying programming language support
for memory handling and structuring. As you said in C++ it would involve
traversing and/or copying. In lisp you have zero copy and GC, also the
whole language is designed to handling sexp (in fact the *source code*
is a sexp). It's also guaranteed to be properly tail-recursive
(differently from C/C++) and that means a lot for common sexp traversal
(which is usually not done like in java or C++, anyway).

As you said in C++ the most useful data structure is a struct or class
with fields. In lisp the original data structure is a tree of stuff
(where stuff is whatever you want, values carry the type, variables are
only bound to values; subtle difference).

I don't see a big issue anyway... just like for FORTRAN or COBOL the
useful structure is the fixed length record, in common lisp you have the sexp
(containing stuff, strings, numbers of about seven different types,
symbols, hashtables and arrays) in C you have mostly structs, arrays and
linked lists and in C++ there are the STL containers. (BTW yes, common
lisp *is* overengineered, the printf-equivalent can also format in roman
numbers:P scheme OTOH is so slim that doesn't have iteration)

Every language has its own preferred ways to doing thing, it shouldn't
surprise that the original efficient way of handling sexps (in lisp) is
actually a PITA in C++.

-- 
Lorenzo Marcantonio
Logos Srl


References