On 08/29/2018 03:58 AM, Stefan Israelsson Tampe wrote:
Hi all, I'm trying to make a python clone in guile. Currently the code
is slow and one of the reasons is the following,
in my pythoon
return 1,2
returns a (values 1 2) in order to get python and scheme to
interoperate. but for python if you use
x = 1,2
then x is the tupple '(1 2) and in guile it is 1. So therefore we wrap
the result for
x=f(10)
as
(set! x (call-with-values (lambda () (f x)) (case-lambda ((x) x) (x x))))
This can be compiled to efficient bytecode but is not done so in
guile. In stead a closure is created at each assignment site and
creating ineficient code.
Any ideas how to improve this (I don't want "return a,b" to mean (list
a b) which is a quick solution
if we want to just stay in python and not interoperate with scheme at
all on this level.
Regards
Stefan
So I'm working on extension languages in Guile. I assume you are always
returning tree-il
values from Python functions. (Unless from functions returning tuples, but how
do you
guarantee that?) You could add a property to your functions and then compile
to CPS and
do the optimization yourself. Then convert to bytecode. But that seems tough.
I assume the use case is being able to call Python code from Guile, so one
would always call
from Scheme using call-with-values?
I am using call-with-values in nx-matlab when the function is declared with
multiple values.
Also, I wonder if we should be "marking" functions with a property to indicate
what the
source language is. The property could be 'language. (If no language assume
'scheme.)
Matt