Date tis 25 juni 2019

I just landed code that makes python iterators deep copyable. This is a feat and depend on deep copying delimited continuations. The code depends on the compiler not to store doubles and integers purely on the stack. If we assume that variables that you set! does not expand out python on guile programs typically will not trigger this problem due to all variable assignments has a set! behind. Else one need to ask the compiler to not inline raw SCM variables. Anyhow now this works if you use module (language python yield),

(define range
 (make-generator (n)
  (lambda (yield n)
    (let lp ((i 0))
      (if (< i n)
          (begin
            (yield i)
            (lp (+ i 1))))))))

And now a python session might look like

>>> import copy
>>> i = range(10)
>>> next(i)
  0
>>> j = copy.deepcopy(i)
>>> next(j)
  1
>>> next(i)
  1

And so on. Deep copying is a difficult subject because sometimes you don't wan't to copy an object but refere to in as a value in a module. Class identities is typically just such an identity which is what you want in 99.99% of the cases. Else there is class constructs that does not automatically do this association. Typically also fluid variables needs to be behave like classes and tags for exceptions and partial-continutions. python on guile should have those guards, but new 3'd party scheme libs needs to take this into consideration and use name-object from (language python persist).

partial continuation does not yet serialize however, but we are almost there. THe stack has references to code points that needs to be translated as an relative adress to an imported module. This is the next step in the developments. The code that enable these serializations and copying is the guile-persists project. PLease note that this is a uggly hack and probably will be difficult to maintain and probably not liked by the guile maintainers. Much better to implement those cinstructs in guile proper. But let's play with this first to get a good starting point.

Happy hacking.


Comments

comments powered by Disqus