mit-scheme-devel
[Top][All Lists]
Advanced

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

Re: [MIT-Scheme-devel] R7RS and values.


From: Matt Birkholz
Subject: Re: [MIT-Scheme-devel] R7RS and values.
Date: Thu, 3 Nov 2016 11:28:18 -0700

> From: Taylor R Campbell <address@hidden>
> Date: Thu, 3 Nov 2016 16:10:34 +0000
> 
> [...]
> LIAR didn't, but SF did.  It would transform
> 
> (receive (x y z) (values a b c)
>   ...)
> 
> into
> 
> (let ((x a) (y b) (z c))
>   ...)
> 
> and thereby avoid the closure altogether.  That's what the integration
> you're deleting did.

I see.  You assume values is integrated into the producer and the
producer into the call-with-values form, an assumption that may often
hold true in hotspots.  Or are you saying you know this is the case in
tests/check.scm, thus the poor showing there?

I have not updated the documentation yet.  In the attached patch I
mention the change in performance and recommend the old optimization
to avoid it.  I don't see much hope for the old optimization without
the programmer-guaranteed restriction.

I might be breaking things (again!).  While I've removed our
restriction on VALUES (that it and only it return to CALL-WITH-
VALUES), I have also removed an "extension" that allowed e.g. cleanup-
noop-nodes to pass along multiple values as if they were one.  It was
not a documented extension, yet losing it will break unwary code.
Perhaps just a mention in the release notes?

diff --git a/doc/ref-manual/procedures.texi b/doc/ref-manual/procedures.texi
index 543aa8c..1e1822f 100644
--- a/doc/ref-manual/procedures.texi
+++ b/doc/ref-manual/procedures.texi
@@ -446,26 +446,72 @@ extent of a call to @var{before} or @var{after} is 
undefined.
 @end example
 @end deffn
 
-The following two procedures support multiple values.
+The following two procedures support multiple values.  Note that
+version 9.3 does not inline these procedures.  Thus they cost more in
+time and space.  To preserve the optimization that 9.2 and earlier
+versions allowed, define your own multiple value forms and observe
+the restriction that they be used together.
+
address@hidden
+(define-integrable (apply-values transmitter receiver)
+  (transmitter receiver))
+
+(define-integrable (return-3 v0 v1 v2)
+  (lambda (receiver)
+    (receiver v0 v1 v2)))
address@hidden example
+
+With the above definitions, a form like
+
address@hidden
+(apply-values (lambda () (return-3 1 2 3))
+              (lambda (a b c)
+                (foo a b)
+                c))
address@hidden
+
+can be transformed first into
+
address@hidden
+((lambda () (lambda (receiver) (receiver 1 2 3)))
+ (lambda (a b c)
+  (foo a b)
+  c))
address@hidden example
+
+and ultimately, by additional substitutions, into
+
address@hidden
+((lambda (a b c)
+   (foo a b)
+   c)
+ 1
+ 2
+ 3)
address@hidden example
+
+also known as
+
address@hidden
+(let ((a 1)
+      (b 2)
+      (c 3))
+  (foo a b)
+  c)
address@hidden example
 
 @deffn procedure call-with-values thunk procedure
 @cindex multiple values, from procedure
 @cindex values, multiple
 @var{Thunk} must be a procedure of no arguments, and @var{procedure}
 must be a procedure.  @var{Thunk} is invoked with a continuation that
-expects to receive multiple values; specifically, the continuation
-expects to receive the same number of values that @var{procedure}
-accepts as arguments.  @var{Thunk} must return multiple values using the
address@hidden procedure.  Then @var{procedure} is called with the
-multiple values as its arguments.  The result yielded by @var{procedure}
-is returned as the result of @code{call-with-values}.
+applies @var{procedure} to @var{thunk}'s return values.  The values
+returned by @var{procedure} are returned by @code{call-with-values}.
 @end deffn
 
 @deffn procedure values object @dots{}
 Returns multiple values.  The continuation in effect when this procedure
-is called must be a multiple-value continuation that was created by
address@hidden  Furthermore it must accept as many values as
-there are @var{object}s.
+is called must accept as many values as there are @var{object}s.
 @end deffn
 
 @node Application Hooks, Generic Dispatch, Continuations, Procedures



reply via email to

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