Date lör 21 oktober 2017

Last time a couple of months ago I finished a first take to implement the python datamodel in scheme and the result pf-object was demoed. Since then there has been some hard work on my free time and now most of the python language is implemented. I will not tuch the python async's interfaces because I thing that guile's fibers is a better approach and cleaner. Anyhow loading the sources and testing it you will find that maybe 90% works but 10% doesn't but that's life when you are a single coder on a hobby project. I will continue to solidify the work. One target is to make the goops play nice with python, you will find that guile's string is the same as python's string but that you can also find byte strings that are simply a bytevetor so now folks now you can load in your ascii files and have nice utilities to parse. The python model has a very rich structure when it comes to functions. I'm not too hapy to wrap functions into classes and want to keep them as such in order to have a nice integration between scheme and python data world. Ther is only one interface added and that is that you can set and get attributes on the functions. This is made via procedure properties and is a rather slow link between function objects and actual functions. A warning, if ou want the def's to take advantage of tail call's don't return in non tail position - that will wrap let/ec constructs and you will build up stack. The python meta object layer should work ok but sofar I have not decided about how the __call__ works for object creation so that possibility is inhibited for now.

Some things are new in this work. A functional python object system is incorporated closely with the language via both new keyword parameters that control this feature in class kreation as well as some sugar to streamline the usage of functional objects. Let's demo

class A(functional=True): pass

a = A()
b = A()

b.x = 1
b.y = 1
b.z = 1
b.w = 1
b.q = 1
b.u = 1
b.r = 1

a.b = b

# Nothing seams to change!!
a.b.x = 2
a.b.x
-> 2
b.x
-> 2

# But this : notation indicate that the objects shall not mutate
# This actually works for normal classes as well via copying but
# is expensive why the need to create a special functional class

> a2 : a.b.y = 2

> a.b.y
1

> b.y
1

> a2.b.y
2

# The : notation is a bit more intelligent if the chain on lhs is a prefix
# of rhs

> a : a.b.z = 2

> a.b.z
2

> b.z
1

> a.b : a.b.w = 2

> a.b.w
2

> b.w
2

# function application suger is not yet implemented but this is how it
# should work

def f(self):
    self.q = self.x + self.y
    return self.q

> A.f=f

> ret = a : a.b.f()

# a.b.x = 2, a.b.y = 1

> ret
3


> b.q
1

> a.b.q
3

def g(self):
    self : self.b.u = self.b.x + self.b.y

> A.g=g

ret = a : a.g()

> b.u
1

> a.b.u
3

def h(self):
    self : self.b.r = self.b.x + self.b.y

> A.h=h

ret = a2 : a.g()

> b.r
1

> a.b.r
1

> a2.b.r
3

Hope you appriciate the hard work and Happy Hacking


Comments

comments powered by Disqus

~ Follow me ~