From: Glen Able
Subject: sexps as generic data format
Date: 
Message-ID: <d9ckgs$5tg$1@newsg1.svr.pol.co.uk>
Hello

If I'm storing data in text files in this sort of format:

; the gary object
(:object "gary"
  :colour :red
  :spigots 5)

then I guess Lisp makes reading and writing easy.

However comments seem to be discarded by 'read'.  So how could I read 
these files and, after modifying the data, write them out again with 
comments intact?

Or is the only sensible solution to add comments as named fields in the 
data structure e.g. (:comment "the gary object")

thank you!

From: Barry Margolin
Subject: Re: sexps as generic data format
Date: 
Message-ID: <barmar-2C9AAD.18424622062005@comcast.dca.giganews.com>
In article <············@newsg1.svr.pol.co.uk>,
 Glen Able <·········@gmail.com> wrote:

> Hello
> 
> If I'm storing data in text files in this sort of format:
> 
> ; the gary object
> (:object "gary"
>   :colour :red
>   :spigots 5)
> 
> then I guess Lisp makes reading and writing easy.
> 
> However comments seem to be discarded by 'read'.  So how could I read 
> these files and, after modifying the data, write them out again with 
> comments intact?

You could redefine #\; to be a macro character that returns a special 
comment object containing the text up to the end of the line.

> Or is the only sensible solution to add comments as named fields in the 
> data structure e.g. (:comment "the gary object")

That seems like a better solution overall.  You're going to have to keep 
the comments somewhere when you read the file into memory anyway, so why 
not put it in a slot in the objects?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Damien R. Sullivan
Subject: Re: sexps as generic data format
Date: 
Message-ID: <d9do23$4jv$1@rainier.uits.indiana.edu>
Barry Margolin <······@alum.mit.edu> wrote:
> Glen Able <·········@gmail.com> wrote:

>> Or is the only sensible solution to add comments as named fields in the 
>> data structure e.g. (:comment "the gary object")
>
>That seems like a better solution overall.  You're going to have to keep 
>the comments somewhere when you read the file into memory anyway, so why 
>not put it in a slot in the objects?

Think of it as your own docstrings.  In fact I'd be a bit surprised if there
weren't an official way to do this already, to making strings accessible with
DOCUMENTATION.

-xx- Damien X-) 
From: Kalle Olavi Niemitalo
Subject: Re: sexps as generic data format
Date: 
Message-ID: <87oe9wkbfq.fsf@Astalo.kon.iki.fi>
········@cs.indiana.edu (Damien R. Sullivan) writes:

> In fact I'd be a bit surprised if there weren't an official way to
> do this already, to making strings accessible with DOCUMENTATION.

You can extend DOCUMENTATION by defining more methods.
From: Peter Seibel
Subject: Re: sexps as generic data format
Date: 
Message-ID: <m2d5qcgyzf.fsf@gigamonkeys.com>
········@cs.indiana.edu (Damien R. Sullivan) writes:

> Barry Margolin <······@alum.mit.edu> wrote:
>> Glen Able <·········@gmail.com> wrote:
>
>>> Or is the only sensible solution to add comments as named fields in the 
>>> data structure e.g. (:comment "the gary object")
>>
>>That seems like a better solution overall.  You're going to have to keep 
>>the comments somewhere when you read the file into memory anyway, so why 
>>not put it in a slot in the objects?
>
> Think of it as your own docstrings.  In fact I'd be a bit surprised if there
> weren't an official way to do this already, to making strings accessible with
> DOCUMENTATION.

Indeed--you can define methods on the generic functios DOCUMENATION
and (SETF DOCUMENTATION)

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Barry Margolin
Subject: Re: sexps as generic data format
Date: 
Message-ID: <barmar-06FBB5.01112524062005@comcast.dca.giganews.com>
In article <··············@gigamonkeys.com>,
 Peter Seibel <·····@gigamonkeys.com> wrote:

> ········@cs.indiana.edu (Damien R. Sullivan) writes:
> 
> > Barry Margolin <······@alum.mit.edu> wrote:
> >> Glen Able <·········@gmail.com> wrote:
> >
> >>> Or is the only sensible solution to add comments as named fields in the 
> >>> data structure e.g. (:comment "the gary object")
> >>
> >>That seems like a better solution overall.  You're going to have to keep 
> >>the comments somewhere when you read the file into memory anyway, so why 
> >>not put it in a slot in the objects?
> >
> > Think of it as your own docstrings.  In fact I'd be a bit surprised if 
> > there
> > weren't an official way to do this already, to making strings accessible 
> > with
> > DOCUMENTATION.
> 
> Indeed--you can define methods on the generic functios DOCUMENATION
> and (SETF DOCUMENTATION)

Except that his data structure is just a list.  Users should not define 
methods on standard generic functions for standard classes.

Instead of using lists, he should use structures or classes, and then 
it's OK to define this method.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***