From: Rob Warnock on
John Thingstad <jpthing(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.
+---------------

In the "Guess the Animal" game included in the CLLIB subsection of
CLOCC[1], the data is stored as a simple tagged binary tree, that is:

(LIST* question-string if-yes-subtree if-no-subtree).

with leaves being subtrees that are strings [instead of conses], e.g.:

(defvar *animals-default-data*
'("Is it an insect" ("Can it sting" "a bee" . "a roach")
"Can it fly" "a duck" . "a penguin"))

That means that the data is *very* easy to write out and read back...


-Rob

[1] http://clocc.cvs.sourceforge.net/*checkout*/clocc/clocc/src/cllib/animals.lisp

-----
Rob Warnock <rpw3(a)rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

From: John Thingstad on
Den Fri, 06 Nov 2009 21:27:03 -0600, skrev Rob Warnock:

> John Thingstad <jpthing(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. +---------------
>
> In the "Guess the Animal" game included in the CLLIB subsection of
> CLOCC[1], the data is stored as a simple tagged binary tree, that is:
>
> (LIST* question-string if-yes-subtree if-no-subtree).
>
> with leaves being subtrees that are strings [instead of conses], e.g.:
>
> (defvar *animals-default-data*
> '("Is it an insect" ("Can it sting" "a bee" . "a roach")
> "Can it fly" "a duck" . "a penguin"))
>
> That means that the data is *very* easy to write out and read back...

Agreed. It annoys me though that classes are just about the only thing
where what is printed can't be read back.I never really understood the
assymetry that there is a print-object but no read-object.
Also it's about the only object where structural equality (equalp)
doesn't work.

This is what makes CLOS the problem rather than the solution. Guess all
this customization comes at a price.

I would have liked a simple-class metaclass (alla simple array) where the
two propositions were furfilled. Maybe I'll write one..
From: Vassil Nikolov on

On Sat, 07 Nov 2009 06:44:34 -0600, John Thingstad <jpthing(a)online.no> said:
> ...
> there is a print-object but no read-object.

There is, but the correspondence is not that trivial: PRINT-OBJECT
is to PRINT & Co. [*] as readtable manipulation is to READ &
Co. [+].

_________
[*] including PRIN1, PRIN1-TO-STRING, WRITE, etc.
[+] READ, READ-FROM-STRING, READ-PRESERVING-WHITESPACE

---Vassil.


--
"Even when the muse is posting on Usenet, Alexander Sergeevich?"
From: Thomas F. Burdick on
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.
From: Pascal Costanza on
John Thingstad 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?

Are you aware of the following link?

http://web.archive.org/web/20040815123650/http://lecture.pentaside.org/paper/persistence-lemmens.txt


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/