Re: load in environment
"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
Guile Introspection
Hi- Is it possible to get introspection information out of Guile (preferably without having to load GOOPS)? For example, how can I write a function that prints its own name? Or, what is the scheme version of the following C code printf("%s %d\n", __FILE__, __LINE__); Thanks in advance, Mike Gran ___ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user
Re: Guile Introspection
On 7/7/07, Mike Gran <[EMAIL PROTECTED]> wrote: Hi- Is it possible to get introspection information out of Guile (preferably without having to load GOOPS)? For example, how can I write a function that prints its own name? You can define a macro to make this happen: (defmacro define-named (name-and-args . body) (let ((name (car name-and-args)) (args (cdr name-and-args))) `(define (,name ,@args) (let ((--function-- ',name)) ,@body Here is an example of how to use it, analogous to using __FUNCTION__ in gcc: (define-named (some-fun) (display --function--) (newline)) Or, what is the scheme version of the following C code printf("%s %d\n", __FILE__, __LINE__); I don't know if there's a way to do this in Guile. Issac ___ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user