unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Taylan Kammer <taylanbayirli@gmail.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: speedup of modifying return values
Date: Wed, 29 Aug 2018 20:46:52 +0200	[thread overview]
Message-ID: <87h8jdc8o3.fsf@gmail.com> (raw)
In-Reply-To: <CAGua6m3D=DOo4-S+xJobiQJpFwnsHDyGKJ16aRPAoAVefTCkJA@mail.gmail.com> (Stefan Israelsson Tampe's message of "Wed, 29 Aug 2018 12:58:16 +0200")

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



  reply	other threads:[~2018-08-29 18:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29 10:58 speedup of modifying return values Stefan Israelsson Tampe
2018-08-29 18:46 ` Taylan Kammer [this message]
2018-08-29 20:54   ` Hans Åberg
2018-08-29 22:53 ` Matt Wette

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h8jdc8o3.fsf@gmail.com \
    --to=taylanbayirli@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=stefan.itampe@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).