unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* call with value
@ 2020-04-12 16:58 Stefan Israelsson Tampe
  2020-04-13  2:34 ` William ML Leslie
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Israelsson Tampe @ 2020-04-12 16:58 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

I have this (on guile 3.0.0),

(define (f x) (call-with-values (lambda () x) (case-lambda ((x) ...) (x
...)))))

and the code does not simplify to (define (f x) x), why?

It would be great to have guile optimize this as in python we have

x=1,0
=> x=(1,0)

And the great thing with python on guile is that we get the same behavior
with (values 1 0) as a r.h.s. so that we get good interoperability between
guile and python.

This is implemented as

(call-with-values (lambda () r.h.s.)
   (case-lambda
      ((x) x)
      (x   x)))

This has nice semantics but is expensive. Many times we can prove that
r.h.s. has a single value return and we would like to be speed optimal for
this case. I do not think that the python compiler should do this analysis
or what do you think?

[-- Attachment #2: Type: text/html, Size: 1106 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: call with value
  2020-04-12 16:58 call with value Stefan Israelsson Tampe
@ 2020-04-13  2:34 ` William ML Leslie
  0 siblings, 0 replies; 2+ messages in thread
From: William ML Leslie @ 2020-04-13  2:34 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

On Mon, 13 Apr 2020 at 02:59, Stefan Israelsson Tampe
<stefan.itampe@gmail.com> wrote:
>
> I have this (on guile 3.0.0),
>
> (define (f x) (call-with-values (lambda () x) (case-lambda ((x) ...) (x ...)))))
>
> and the code does not simplify to (define (f x) x), why?
>
> It would be great to have guile optimize this as in python we have
>
> x=1,0
> => x=(1,0)
>
> And the great thing with python on guile is that we get the same behavior with (values 1 0) as a r.h.s. so that we get good interoperability between guile and python.
>

Hi Stis,

I'm not sure if I mentioned this to you earlier, but I'm worried that
this won't be a great user experience.  When a python function returns
a tuple, whether "implicitly" as part of the return statement or not,
the invoker still gets one tuple, and is free to unpack it.  If I were
to call a function that returned a 1-value tuple and instead it got
unpacked for me, I would be very confused.

Similarly, if a python function `f` returns a tuple and I invoke
`g(f(x))`, I expect g to receive one tuple; not a number of arguments.
I'd have to say `g(*f(x))` if I wanted it to receive the items as
argument values.

-- 
William Leslie

Notice:
Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely MAY reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to DENY YOU THOSE RIGHTS would be illegal without
prior contractual agreement.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-13  2:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12 16:58 call with value Stefan Israelsson Tampe
2020-04-13  2:34 ` William ML Leslie

unofficial mirror of guile-devel@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guile-devel/0 guile-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guile-devel guile-devel/ https://yhetil.org/guile-devel \
		guile-devel@gnu.org
	public-inbox-index guile-devel

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.lisp.guile.devel
	nntp://news.gmane.io/gmane.lisp.guile.devel


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git