Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Some Progress!

1 view
Skip to first unread message

Nonzero

unread,
Nov 2, 2001, 9:02:09 PM11/2/01
to
Hello all,
thanks for the help

I have finally made some progress. By using
(setq data-file (open "array-data.dat" :direction output
:if-exists :overwrite
:if-does-not-exist :create))

(let ((*print-array* t))
(print my-array data-file))

This allows me to write my array to a file.

Whewph!

But now the question is how do I get it back?

Is there something like a *read-array* command, and if so, what do I
need to type. I can't seem to find it anywhere.


Thanks again all
-Nonzero314

Pierre R. Mai

unread,
Nov 3, 2001, 12:11:44 AM11/3/01
to
Nonze...@hotmail.com (Nonzero) writes:

> I have finally made some progress. By using
> (setq data-file (open "array-data.dat" :direction output
> :if-exists :overwrite
> :if-does-not-exist :create))
>
> (let ((*print-array* t))
> (print my-array data-file))

What you really want is:

(defun save-my-data (array filename)
(with-open-file (stream filename :direction :output)
(with-standard-io-syntax
;; If you've got shared structures in array that you want
;; preserved, bind *print-circle* to T here, too.
;; You might also want to bind *read-eval* to nil here,
;; if you are going to bind it to nil when reading.
(write my-array stream))))

> But now the question is how do I get it back?

(defun read-my-data (filename)
(with-open-file (stream filename)
(with-standard-io-syntax
;; You might want to bind *read-eval* to nil here,
;; for security reasons. See HyperSpec for detail.
(read stream))))

This function will return the read-in array.

> Is there something like a *read-array* command, and if so, what do I
> need to type. I can't seem to find it anywhere.

See the HyperSpec, chapter 21 (Printer), 22 (Reader) and 20 (Streams).
You might also want to skim a couple of the other chapters as well.

The HyperSpec is availabe at

http://www.xanalys.com/software_tools/reference/HyperSpec/

Regs, Pierre.

--
Pierre R. Mai <pm...@acm.org> http://www.pmsf.de/pmai/
The most likely way for the world to be destroyed, most experts agree,
is by accident. That's where we come in; we're computer professionals.
We cause accidents. -- Nathaniel Borenstein

Alexey Dejneka

unread,
Nov 3, 2001, 1:04:10 AM11/3/01
to
Hello,

Nonze...@hotmail.com (Nonzero) writes:
> (setq data-file (open "array-data.dat" :direction output

^^^^^^
should be :output


> :if-exists :overwrite
> :if-does-not-exist :create))
>
> (let ((*print-array* t))
> (print my-array data-file))
>
> This allows me to write my array to a file.
>
> Whewph!
>
> But now the question is how do I get it back?

(with-open-file (data-file "array-data.dat" :direction :input)
(setq *my-array* (read data-file)))

Don't use global variable names without *-s around (even in a REPL dialog).

Regards,
Alexey Dejneka

--
(loop with nil = t do ...)

0 new messages