From: chenyu
Subject: newbie question: how to serialize a variable
Date: 
Message-ID: <ba9747f1.0401011657.57acb661@posting.google.com>
Hello, 
I have created a AI problem by random. Now I have to compare 4 search
algorithms.

Is it possible for me to serialize the variable of problem for later
useage? If yes, how to do it?


Thank you for your attention. 
best regards/chenyu

From: Justin Dubs
Subject: Re: newbie question: how to serialize a variable
Date: 
Message-ID: <2e262238.0401012318.4cf9bc0b@posting.google.com>
·········@21cn.com (chenyu) wrote in message news:<····························@posting.google.com>...
> Hello, 
> I have created a AI problem by random. Now I have to compare 4 search
> algorithms.
> 
> Is it possible for me to serialize the variable of problem for later
> useage? If yes, how to do it?

Assuming your data is readable:

> (defvar *my-data* '(1 2 3 4))
(1 2 3 4)
> (with-open-file (saved-data "saved-data" :direction :output)
      (format saved-data "~A" *my-data*))
nil

Then, later on:

> (defvar *my-data*)
nil
> (with-open-file (saved-data "saved-data" :direction :input)
      (setf *my-data* (read saved-data)))
(1 2 3 4)

You'll also want to look into the other keywords that can be supplied
to open, such as :if-exists and :if-not-exists.

Hope that helps.

Justin Dubs
From: chenyu
Subject: Re: newbie question: how to serialize a variable
Date: 
Message-ID: <ba9747f1.0401030446.545d44c@posting.google.com>
Thank you for both your helps.

kind regards/chenyu

······@eos.ncsu.edu (Justin Dubs) wrote in message news:<····························@posting.google.com>...
> ·········@21cn.com (chenyu) wrote in message news:<····························@posting.google.com>...
> > Hello, 
> > I have created a AI problem by random. Now I have to compare 4 search
> > algorithms.
> > 
> > Is it possible for me to serialize the variable of problem for later
> > useage? If yes, how to do it?
> 
> Assuming your data is readable:
> 
> > (defvar *my-data* '(1 2 3 4))
>  (1 2 3 4)
> > (with-open-file (saved-data "saved-data" :direction :output)
>       (format saved-data "~A" *my-data*))
> nil
> 
> Then, later on:
> 
> > (defvar *my-data*)
>  nil
> > (with-open-file (saved-data "saved-data" :direction :input)
>       (setf *my-data* (read saved-data)))
> (1 2 3 4)
> 
> You'll also want to look into the other keywords that can be supplied
> to open, such as :if-exists and :if-not-exists.
> 
> Hope that helps.
> 
> Justin Dubs
From: Barry Margolin
Subject: Re: newbie question: how to serialize a variable
Date: 
Message-ID: <barmar-1B9068.23184101012004@netnews.attbi.com>
In article <····························@posting.google.com>,
 ·········@21cn.com (chenyu) wrote:

> Hello, 
> I have created a AI problem by random. Now I have to compare 4 search
> algorithms.
> 
> Is it possible for me to serialize the variable of problem for later
> useage? If yes, how to do it?

If it's some kind of basic list structure, you can use WRITE or PRIN1 to 
write it to a a file.

If it includes objects that don't have a readable printed 
representation, there's a SAVE-OBJECT function in the Lisp archives that 
may do what you need.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA