From: Timofei Shatrov on
On Fri, 06 Nov 2009 10:08:46 -0600, John Thingstad <jpthing(a)online.no> tried to
confuse everyone with this message:

>I am writing a 'guess the animal' game for my Lisp book of games.
>This game uses a binary deduction tree.
>The thing is this tree needs to be stored to and loaded from disk. This
>is a simple game and I don't want it to depend on external libraries like
>object-store. I figure the best way to do this is to store the CLOS tree
>as the code I would write to contruct the tree.

No, this is a bad idea. If you're going to store objects, using external
libraries such as CL-STORE is the way to go. But in your case, you can easily
store all your data as a list, which is trivial to save or read from disk.

--
|Don't believe this - you're not worthless ,gr---------.ru
|It's us against millions and we can't take them all... | ue il |
|But we can take them on! | @ma |
| (A Wilhelm Scream - The Rip) |______________|
From: John Thingstad on
The Sun, 08 Nov 2009 04:39:35 -0800, Thomas F. Burdick wrote:

> On Nov 6, 5:08 pm, John Thingstad <jpth...(a)online.no> wrote:
>> I am  writing a 'guess the animal' game for my Lisp book of games. This
>> game uses a binary deduction tree. The thing is this tree needs to be
>> stored to and loaded from disk. This is a simple game and I don't want
>> it to depend on external libraries like object-store. I figure the best
>> way to do this is to store the CLOS tree as the code I would write to
>> contruct the tree. That way I can just use read to recontruct it. Never
>> the less the code here looks a bit uggy at least in (defmethod store
>> ((item tree-node))). Do you see a better way to do this?
>
> Do you really need to use defclass here? If you can get by with
> structures, they serialize and de-serialize nicely as is.

Yes, that's what I ended up doing.

(defstruct (animal-name (:type list))
item
left-child
right-child)

(defun questionp (string) (char= (aref string (1- (length string)) #\?))
(defun animalp (string) (not (questionp string))

--
John Thingstad
From: Thomas F. Burdick on
John Thingstad wrote:
> The Sun, 08 Nov 2009 04:39:35 -0800, Thomas F. Burdick wrote:
>
>> On Nov 6, 5:08 pm, John Thingstad <jpth...(a)online.no> wrote:
>>> I am  writing a 'guess the animal' game for my Lisp book of games. This
>>> game uses a binary deduction tree. The thing is this tree needs to be
>>> stored to and loaded from disk. This is a simple game and I don't want
>>> it to depend on external libraries like object-store. I figure the best
>>> way to do this is to store the CLOS tree as the code I would write to
>>> contruct the tree. That way I can just use read to recontruct it. Never
>>> the less the code here looks a bit uggy at least in (defmethod store
>>> ((item tree-node))). Do you see a better way to do this?
>>
>> Do you really need to use defclass here? If you can get by with
>> structures, they serialize and de-serialize nicely as is.
>
> Yes, that's what I ended up doing.
>
> (defstruct (animal-name (:type list))
> item
> left-child
> right-child)
>
> (defun questionp (string) (char= (aref string (1- (length string)) #\?))
> (defun animalp (string) (not (questionp string))

Why the (:type list)? Structure objects serialize just fine.
From: John Thingstad on
The Mon, 09 Nov 2009 17:02:32 +0000, Thomas F. Burdick wrote:

> John Thingstad wrote:
>> The Sun, 08 Nov 2009 04:39:35 -0800, Thomas F. Burdick wrote:
>>
>>> On Nov 6, 5:08 pm, John Thingstad <jpth...(a)online.no> wrote:
>>>> I am  writing a 'guess the animal' game for my Lisp book of games.
>>>> This game uses a binary deduction tree. The thing is this tree needs
>>>> to be stored to and loaded from disk. This is a simple game and I
>>>> don't want it to depend on external libraries like object-store. I
>>>> figure the best way to do this is to store the CLOS tree as the code
>>>> I would write to contruct the tree. That way I can just use read to
>>>> recontruct it. Never the less the code here looks a bit uggy at least
>>>> in (defmethod store ((item tree-node))). Do you see a better way to
>>>> do this?
>>>
>>> Do you really need to use defclass here? If you can get by with
>>> structures, they serialize and de-serialize nicely as is.
>>
>> Yes, that's what I ended up doing.
>>
>> (defstruct (animal-name (:type list))
>> item
>> left-child
>> right-child)
>>
>> (defun questionp (string) (char= (aref string (1- (length string))
>> #\?)) (defun animalp (string) (not (questionp string))
>
> Why the (:type list)? Structure objects serialize just fine.

It's easier to debug when you can see the entire tree.
Remeber in the animal guessing game it tries to learn the new animal if
it can't guess it and it is easier to just look at a dump of the list
than to drill through it with the inspector. Oh, and the structure name
should be node, not animal-name.




--
John Thingstad