guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: load in environment


From: Jon Wilson
Subject: Re: load in environment
Date: Mon, 09 Jul 2007 13:22:05 -0400
User-agent: Thunderbird 1.5.0.12 (X11/20070604)

Hi Marco,
What does PURIFY-MODULE! actually do? The docstring is just almost clear enough for me to understand its purpose.

`purify-module!' is a procedure in the (guile) module.

Removes bindings in MODULE which are inherited from the (guile) module.

I think the mechanics of what it does are clear enough, but from my understanding of modules, it seems essentially useless. MAKE-MODULE returns an empty module with no bindings, which inherits from no other module. Calling PURIFY-MODULE! on such an empty module would thus be a no-op. The only reason that a module would inherit any bindings from the (guile) module would be if it used (via MODULE-USE! or some such) the guile module, whether directly, or via another module. So, if you want a module which does not inherit any bindings from (guile), then it seems the solution would be to simply not have your module use (guile), or any module which uses (guile). I suppose that if you used a module which used (guile), that it might be of some use, but presumably, the module that uses (guile) does so for a reason, and removing those bindings might cause it to stop working, in which case using that module at all would be pointless. Clearly I've misunderstood something or other.

Your assessment of the situation seems to be correct. I have a Scheme-like declarative ASL.

Is there any reason why you chose to read and eval the file manually rather than using LOAD with the current module set to asl-interp?

Finally, I'd like to allow the user to generate the declarations in the ASL programmatically. Naturally, this requires adding things like lambda and + and stuff into asl-interp. How can I evaluate the safety of various things I might add in? I'd even somewhat like to allow LOAD, so that the ASL declarations could be split out into multiple files if the user wanted.
Regards,
Jon

Marco Maggi wrote:
"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)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]