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!
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 ***
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-)
········@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.
········@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/
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 ***