* speedup of modifying return values
@ 2018-08-29 10:58 Stefan Israelsson Tampe
2018-08-29 18:46 ` Taylan Kammer
2018-08-29 22:53 ` Matt Wette
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2018-08-29 10:58 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 797 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 1116 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: speedup of modifying return values
2018-08-29 10:58 speedup of modifying return values Stefan Israelsson Tampe
@ 2018-08-29 18:46 ` Taylan Kammer
2018-08-29 20:54 ` Hans Åberg
2018-08-29 22:53 ` Matt Wette
1 sibling, 1 reply; 4+ messages in thread
From: Taylan Kammer @ 2018-08-29 18:46 UTC (permalink / raw)
To: Stefan Israelsson Tampe; +Cc: guile-devel
Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
> 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.
Sounds like a fun project. :-)
Idea:
Make Python tuples a new data type, instead of multi-values.
The fact that they can be stored in a single storage location in Python
means that they are actually a data type, only special-handled for
automatic destructuring in some places...
Therefore, I would represent them as a record type under the hood.
Maybe one with a single field that contains a list or a vector.
I would then compile Python syntax that destructures tuples into
corresponding Guile code that destructures them also.
> Regards
> Stefan
Happy hacking,
Taylan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: speedup of modifying return values
2018-08-29 18:46 ` Taylan Kammer
@ 2018-08-29 20:54 ` Hans Åberg
0 siblings, 0 replies; 4+ messages in thread
From: Hans Åberg @ 2018-08-29 20:54 UTC (permalink / raw)
To: Taylan Kammer; +Cc: guile-devel
> On 29 Aug 2018, at 20:46, Taylan Kammer <taylanbayirli@gmail.com> wrote:
>
> Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
>
>> 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.
>
> Sounds like a fun project. :-)
>
> Idea:
>
> Make Python tuples a new data type, instead of multi-values.
>
> The fact that they can be stored in a single storage location in Python
> means that they are actually a data type, only special-handled for
> automatic destructuring in some places...
Indeed, the problem is that in Scheme, (list f x₀ …), using normal infix tuple notation, creates the deferred function object f(x₀, …), and I found it hard to write a normal function call language on top of that.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: speedup of modifying return values
2018-08-29 10:58 speedup of modifying return values Stefan Israelsson Tampe
2018-08-29 18:46 ` Taylan Kammer
@ 2018-08-29 22:53 ` Matt Wette
1 sibling, 0 replies; 4+ messages in thread
From: Matt Wette @ 2018-08-29 22:53 UTC (permalink / raw)
To: guile-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-08-29 22:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-29 10:58 speedup of modifying return values Stefan Israelsson Tampe
2018-08-29 18:46 ` Taylan Kammer
2018-08-29 20:54 ` Hans Åberg
2018-08-29 22:53 ` Matt Wette
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).