unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Marco Maggi" <marco.maggi-ipsu@poste.it>
To: "guile-user" <guile-user@gnu.org>
Subject: Re: load in environment
Date: Sat,  7 Jul 2007 10:52:53 +0200	[thread overview]
Message-ID: <JKSWO5$0078B82A71149C27C45073701CF84AA7@poste.it> (raw)

"Jon Wilson" wrote:
>I'm writing a function to load up some data from a file and
>stick it in a hash table.

Lemmesee if I get it:

1. data representation is stored in a file;
2. the  representation  format  is an  Application  Specific
   Language (ASL), so the file is really a script in ASL;
3. ASL happens to be Scheme-like;
4. to  convert  the   file  representation  in  a  process's
   internal representation the script must be evaluatd in an
   ASL interpreter;
5. nobody  wants the ASL  script to  mess with  the process'
   state or, worst, mess with the file system, etc;

this can be done using pure modules.


(use-modules (ice-9 rdelim))

(define (make-asl-interp funcs)
  (let ((asl-interp (make-module)))
    (purify-module! asl-interp)
    (for-each (lambda (p)
		(module-define! asl-interp (car p) (cdr p)))
      funcs)
    asl-interp))

(define (asl-eval file-name)
  (let* ((data-table	(make-hash-table))
         (item		(lambda (name text number)
			  (hash-set! data-table name
				     (make-item text number))))
	 (asl-interp	(make-asl-interp (list
					  (cons 'item item)))))
    (with-input-from-file file-name
      (lambda ()
	(eval-string (read-delimited "") asl-interp)))
    data-table))

;; ------------------------------------------------------------

(define make-item list)
(define table (asl-eval "data.asl"))

(format #t "dumping table:~%")
(hash-for-each (lambda (key val)
		 (format #t "~/key ~S, val ~S~%" key val))
	       table)

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



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


             reply	other threads:[~2007-07-07  8:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-07  8:52 Marco Maggi [this message]
2007-07-09 17:22 ` load in environment Jon Wilson
  -- strict thread matches above, loose matches on Subject: below --
2007-07-06  3:43 Jon Wilson
2007-07-06  4:26 ` Stephen Compall
2007-07-06  5:19   ` Jon Wilson
2007-07-06  6:03     ` Stephen Compall
2007-07-06  6:06       ` Jon Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='JKSWO5$0078B82A71149C27C45073701CF84AA7@poste.it' \
    --to=marco.maggi-ipsu@poste.it \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).