unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Loading and saving scheme expressions
@ 2002-06-09  6:14 Joris van der Hoeven
  2002-06-09  6:48 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Joris van der Hoeven @ 2002-06-09  6:14 UTC (permalink / raw)
  Cc: vdhoeven


Hi *,

Is there a simple way to load or save scheme expressions,
such as to allow things like

(set! var (load-expr "data-file"))
(save-expr "data-file" '(1 2 3))


-----------------------------------------------------------
Joris van der Hoeven <vdhoeven@texmacs.org>
http://www.texmacs.org: GNU TeXmacs scientific text editor
http://www.math.u-psud.fr/~vdhoeven: personal homepage
-----------------------------------------------------------


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Loading and saving scheme expressions
  2002-06-09  6:14 Loading and saving scheme expressions Joris van der Hoeven
@ 2002-06-09  6:48 ` Thien-Thi Nguyen
  2002-06-09 18:53   ` Bobby D. Bryant
  0 siblings, 1 reply; 4+ messages in thread
From: Thien-Thi Nguyen @ 2002-06-09  6:48 UTC (permalink / raw)
  Cc: guile-user, vdhoeven

   From: Joris van der Hoeven <Joris.VanDerHoeven@math.u-psud.fr>
   Date: Sun, 9 Jun 2002 08:14:14 +0200 (MET DST)

   (set! var (load-expr "data-file"))
   (save-expr "data-file" '(1 2 3))

how about:

 (define (load-expr file)
   (read (open-file file OPEN_READ)))
 
 (define (save-expr file value)
   (write value (open-file file OPEN_WRITE))
   (flush-all-ports))
 
 ;;; testing
 (save-expr "xxx" '(1 2 3))
 (define var (load-expr "xxx"))
 (format #t "var: ~A\n" var)

note the call to `flush-all-ports'.  try this w/ "guile -s".

thi

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Loading and saving scheme expressions
  2002-06-09  6:48 ` Thien-Thi Nguyen
@ 2002-06-09 18:53   ` Bobby D. Bryant
  2002-06-10 16:49     ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: Bobby D. Bryant @ 2002-06-09 18:53 UTC (permalink / raw)


On 2002.06.09 00:48:59 -0600 Thien-Thi Nguyen wrote:

> how about:
> 
>  (define (load-expr file)
>    (read (open-file file OPEN_READ)))
> 
>  (define (save-expr file value)
>    (write value (open-file file OPEN_WRITE))
>    (flush-all-ports))

Is there a way to force pretty-printing to the file?  I've been using 
GUILE for things like user preferences, but if the program modifies it 
and writes it back to the file then it has to be re-formatted for human 
consumption (e.g., if the user wants to hand-edit his/her preferences).

Thanks,

Bobby Bryant
Austin, Texas

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Loading and saving scheme expressions
  2002-06-09 18:53   ` Bobby D. Bryant
@ 2002-06-10 16:49     ` Marius Vollmer
  0 siblings, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2002-06-10 16:49 UTC (permalink / raw)
  Cc: guile-user

"Bobby D. Bryant" <bdbryant@mail.utexas.edu> writes:

> Is there a way to force pretty-printing to the file?

There is the (ice-9 pretty-print) module.

    guile> (use-modules (ice-9 pretty-print))
    guile> (pretty-print '(define (foo) (+ a b)) #:width 10)
    (define (foo)
      (+ a b))

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-06-10 16:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-09  6:14 Loading and saving scheme expressions Joris van der Hoeven
2002-06-09  6:48 ` Thien-Thi Nguyen
2002-06-09 18:53   ` Bobby D. Bryant
2002-06-10 16:49     ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).