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
·········@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
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
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