How to check / export / serialize the environment (trick) Schemes

I would like to export or replicate the schema environment to another process. The algorithm that I present will do something like this to serialize:

(map (lambda (var val) (display (quasiquote (define ,var ,val))
                       (newline))
     (get-current-environment))

And then I read / eval on the other end.

However, although there are functions that return the current environment, they are in some internal format, which I cannot just mapcross. How can I “walk” around the environment as described above? Alternatively, how else can I replicate the environment to another process?

+3
source share
2 answers

You can decompose the so-called "current environment" as follows:

(define (get-current-binding-list)
        (let* ((e (current-module))  ;; assume checking current-module

               (h (struct-ref e 0))  ;; index 0 is current vars hashtable
              )
       (hash-map->list cons h)  ;; return a vars binding list
    ))

(get-current-binding-list), . , , (-, ). , : var:

(define abc 5)

(let ((vl (get-current-binding-list)))
      (assoc-ref vl 'abc)
      )

== > #<variable 9bb5108 value: 5> " " "abc". -ref.

, - , var-name var-value.

, , , , . , .

+2

Scheme. , () . , FFI. .

+2

All Articles