[Top][All Lists]

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

Re: Auto compile from many different languages that interoperates with g

From: Stefan Israelsson Tampe
Subject: Re: Auto compile from many different languages that interoperates with guile
Date: Sat, 9 Sep 2017 16:24:28 +0200

Hi, I've also playing with functional objects e.g. objects that updates functionally meaning that the objects are non mutating. I added a little suger to handle this in my python to prolog compiler and now we can do this:


# Note that the functional parent means that the class is managed using
# functional approach this also constrain that all parent classes is also
# functional else bugs will appear.

class A(functional):
    x = 1
    def __init__(self,y):
        self.x = y

class B(functional):
    y = A(1)
    def __init__(self,y):
a = A(2)
b1 = B(a)

# note that when setting things we update create a new object and this is the
# syntactic suger 
b2 : b1.y.x = 3  # translates to (set! b2 (fset-x b1 '(y x) 3))
b3 : b2.y.y = 4


# there is a nice scheme interface to use this in pf-objects library in the
# code base

;;; ("A" 1)

;;; ("A" 1)

;;; ("b1" 2)

;;; ("b2" 3)

;;; ("b3" 4)

On Fri, Sep 1, 2017 at 10:45 PM, Stefan Israelsson Tampe <address@hidden> wrote:

I am maintaining a prolog->scheme compiler and a python->scheme compiler. The nice thing with those implementation is that they work well with the guile module system and are proper scheme functions and variables etc. So python objects can be treated as goops objects and prolog predicates can be used in kanren etc.

There is a headake though. When loading a module from one language to another language the autocompilation fails. It would be nice to load a python module and work with it from scheme land and vice versa.

One problem is the following funciton in system base compile

(define* (compile-file file #:key
                       (output-file #f)
                       (from (current-language))
                       (to 'bytecode)
                       (env (default-environment from))
                       (opts '())
                       (canonicalization 'relative))

form is either specified or current-language and what I propose is to add a knob that enables another version of the default for from e.g. something like the following.

(define %extension-map '((("py" "python") python) ((("pl" "prolog") prolog) (("scm") scheme)))
(define %use-extension-map #f)
(define (default-from-file file)
  (define default (current-language))
  (if %use-extension-map       
       (let* ((ext   (get-extension file))
               (lang  (find-language ext %extension-map)))
           (if lang lang default))))

(define* (compile-file file #:key
                       (output-file #f)
                       (from (default-from file))
                       (to 'bytecode)
                       (env (default-environment from))
                       (opts '())
                       (canonicalization 'relative))


I think that we already have variables that discovers the source files that guile can compile and I don't think that we should get name clashes as long as we use the prefix (languge prolog module) as a prefix for modules in other languages than scheme.


reply via email to

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