<div dir="ltr"><div><div>I am deeply impressed.<br><br></div>Python&#39;s <span class="">Guido van Rossum is often suspected of owning a time machine,<br></span></div><span class="">but apparently you have one too...<br><br>
<br></span></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/11 Jay McCarthy <span dir="ltr">&lt;<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Thu, Jul 11, 2013 at 1:52 PM, Stephan Houben &lt;<a href="mailto:stephanh42@gmail.com">stephanh42@gmail.com</a>&gt; wrote:<br>
&gt; Hi Jay,<br>
&gt;<br>
&gt; So what about keyword return values?<br>
&gt; Both because of symmetry and because getting three return values straight is<br>
&gt; just as hard as getting three arguments straight.<br>
<br>
</div>That&#39;s old news:<br>
<br>
<a href="https://github.com/jeapostrophe/exp/blob/master/values.ss" target="_blank">https://github.com/jeapostrophe/exp/blob/master/values.ss</a><br>
<br>
FWIW, keywords aren&#39;t built-in in Racket for function calls, so this<br>
approach to them in function returns *is* symmetric.<br>
<span class="HOEnZb"><font color="#888888"><br>
Jay<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
&gt; Stephan Houben<br>
&gt;<br>
&gt; Op 11 jul. 2013 21:39 schreef &quot;Jay McCarthy&quot; &lt;<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>&gt; het<br>
&gt; volgende:<br>
&gt;<br>
&gt;&gt; I prefer to think of values as being justified by not restricting the<br>
&gt;&gt; arity of continuations.<br>
&gt;&gt;<br>
&gt;&gt; (let/cc k<br>
&gt;&gt;  (k 1 2 3))<br>
&gt;&gt;<br>
&gt;&gt; (let/cc k<br>
&gt;&gt;  (k))<br>
&gt;&gt;<br>
&gt;&gt; etc.<br>
&gt;&gt;<br>
&gt;&gt; define-values &amp; let-values create N-arity continuations whereas<br>
&gt;&gt; call-with-values creates an any arity context<br>
&gt;&gt;<br>
&gt;&gt; Jay<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Jul 11, 2013 at 12:23 PM, Laurent &lt;<a href="mailto:laurent.orseau@gmail.com">laurent.orseau@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; Ah that unfortunately explains a lot. Thank you Matthew for this<br>
&gt;&gt; &gt; explanation.<br>
&gt;&gt; &gt; It&#39;s too bad that one needs to throw away nice semantics for speed...<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Neil&#39;s macro idea may then well be one of the best intermediate<br>
&gt;&gt; &gt; solutions<br>
&gt;&gt; &gt; then.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Jens, thanks for all the links, they are quite informative.<br>
&gt;&gt; &gt; Indeed, quite a number of people seem unhappy with `values&#39;.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; However, since I did not find an answer for the following, I will risk<br>
&gt;&gt; &gt; this<br>
&gt;&gt; &gt; anyway:<br>
&gt;&gt; &gt; Then why not return lists instead of values? Performance problem again?<br>
&gt;&gt; &gt; There would not be such a thing as &quot;multiple return values&quot; though, and<br>
&gt;&gt; &gt; one<br>
&gt;&gt; &gt; should not see them this way.<br>
&gt;&gt; &gt; Several values returned in a list is just a list, i.e., a single return<br>
&gt;&gt; &gt; value. Then there are helpers to bind several values from a list, etc.<br>
&gt;&gt; &gt; No need for `apply-values&#39; or `call-with-values&#39;, just use `apply&#39;.<br>
&gt;&gt; &gt; Therefore returning `(list 1)&#39; would of course be different from<br>
&gt;&gt; &gt; returning<br>
&gt;&gt; &gt; `1&#39;, but if you don&#39;t see them as multiple return values, it&#39;s not<br>
&gt;&gt; &gt; inconsistent.<br>
&gt;&gt; &gt; The type of the procedure  would tell what is returned anyway.<br>
&gt;&gt; &gt; Some languages like Python, PHP (and Matlab?) do that, and I find this<br>
&gt;&gt; &gt; more<br>
&gt;&gt; &gt; convenient than `values&#39;.<br>
&gt;&gt; &gt; A &quot;problem&quot; would then be quieter errors for multiple/single value<br>
&gt;&gt; &gt; mismatch,<br>
&gt;&gt; &gt; but I don&#39;t really see this one as important.<br>
&gt;&gt; &gt; I also don&#39;t see the need for a different data type like `sequences&#39; as<br>
&gt;&gt; &gt; they<br>
&gt;&gt; &gt; call it in Jen&#39;s thread.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; When I use `values&#39;, either I (have to) bind them directly to<br>
&gt;&gt; &gt; identifiers,<br>
&gt;&gt; &gt; or I turn them into a list of values to manipulate them otherwise.<br>
&gt;&gt; &gt; The above would make this much easier and simpler I suspect.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Laurent<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Thu, Jul 11, 2013 at 5:18 PM, Matthew Flatt &lt;<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>&gt;<br>
&gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; To elaborate on &quot;currently not possible&quot; (because this idea shows up<br>
&gt;&gt; &gt;&gt; from time to time), allowing splicing of results in function-call<br>
&gt;&gt; &gt;&gt; subexpressions would break equivalences that are currently exploited by<br>
&gt;&gt; &gt;&gt; macros and the compiler.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; For example, many macros assume that<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  (rator rand1 rand2 ... randn)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; can be rewritten as<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  (let ([r rator]<br>
&gt;&gt; &gt;&gt;        [a1 rand1]<br>
&gt;&gt; &gt;&gt;        [a2 rand2]<br>
&gt;&gt; &gt;&gt;        ...<br>
&gt;&gt; &gt;&gt;        [an randn])<br>
&gt;&gt; &gt;&gt;    (r a1 a2 ... an))<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; That would not be the case if the `rand&#39;s can produce multiple values.<br>
&gt;&gt; &gt;&gt; (I assume that you don&#39;t want to allow binding multiple values to a<br>
&gt;&gt; &gt;&gt; variable in `let&#39;.) I think that disallowing this kind of<br>
&gt;&gt; &gt;&gt; transformation would make many macros more difficult to implement ---<br>
&gt;&gt; &gt;&gt; and maybe impossible, in some cases.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; The Racket compiler takes advantage of transformations like the one<br>
&gt;&gt; &gt;&gt; above to speed up your code. Although the compiler could still perform<br>
&gt;&gt; &gt;&gt; transformations when the relevant subexpressions are known to be<br>
&gt;&gt; &gt;&gt; single-valued, I think the transformations would apply much less often<br>
&gt;&gt; &gt;&gt; than now.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Along similar lines, various tools can tell statically you that<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  (cons e1 e2 e3)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; will be an arity error (assuming that `cons&#39; is the usual binding).<br>
&gt;&gt; &gt;&gt; That kind of support would become much weaker, since `e2&#39; might return<br>
&gt;&gt; &gt;&gt; zero values while `e1&#39; and `e3&#39; return a single value.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; In short, the kind of splicing that you suggest is a significant sense<br>
&gt;&gt; &gt;&gt; more &quot;dynamic&quot; than Racket. You could always embed such a dynamic<br>
&gt;&gt; &gt;&gt; language in Racket. Due to macros, however, I don&#39;t think it would work<br>
&gt;&gt; &gt;&gt; to re-interpret our existing code as being written in that language.<br>
&gt;&gt; &gt;&gt; And due to the extra constraints on the compiler and run-time system,<br>
&gt;&gt; &gt;&gt; I&#39;m certain that it would perform worse than Racket. Overall, my sense<br>
&gt;&gt; &gt;&gt; is that the potential extra convenience of splicing values is not worth<br>
&gt;&gt; &gt;&gt; the costs.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; At Thu, 11 Jul 2013 10:42:52 -0400, Matthias Felleisen wrote:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Your uses of values are covered in apply/map/append/list trickeries.<br>
&gt;&gt; &gt;&gt; &gt; Using<br>
&gt;&gt; &gt;&gt; &gt; values might be more elegant, but yes, it&#39;s currently not possible.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; On Jul 11, 2013, at 8:56 AM, Laurent wrote:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; In some postfix languages, if a procedure returns multiple values,<br>
&gt;&gt; &gt;&gt; &gt; &gt; these<br>
&gt;&gt; &gt;&gt; &gt; values can be used directly as multiple arguments to another<br>
&gt;&gt; &gt;&gt; &gt; procedure<br>
&gt;&gt; &gt;&gt; &gt; call,<br>
&gt;&gt; &gt;&gt; &gt; i.e., they are &quot;spliced&quot; in the latter call.<br>
&gt;&gt; &gt;&gt; &gt; &gt; In an extended Racket, this would look like this:<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; (+ (values 1 2) (values 3 4))<br>
&gt;&gt; &gt;&gt; &gt; &gt; would be equivalent to<br>
&gt;&gt; &gt;&gt; &gt; &gt; (+ 1 2 3 4)<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; (map values &#39;(0 1 2) &#39;(a b c))<br>
&gt;&gt; &gt;&gt; &gt; &gt; would return<br>
&gt;&gt; &gt;&gt; &gt; &gt; &#39;(0 a 1 b 2 c)<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; (call-with-values (lambda()(my-proc ....)) list)<br>
&gt;&gt; &gt;&gt; &gt; &gt; would simply be<br>
&gt;&gt; &gt;&gt; &gt; &gt; (list (my-proc ....))<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; (values (values 1 2) (values &#39;a &#39;b))<br>
&gt;&gt; &gt;&gt; &gt; &gt; would be equivalent to<br>
&gt;&gt; &gt;&gt; &gt; &gt; (values 1 2 &#39;a &#39;b)<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; Correct me if I&#39;m wrong, but I think all the cases where this<br>
&gt;&gt; &gt;&gt; &gt; &gt; feature<br>
&gt;&gt; &gt;&gt; &gt; &gt; should<br>
&gt;&gt; &gt;&gt; &gt; be useful currently throws an error, so it would probably break only<br>
&gt;&gt; &gt;&gt; &gt; very<br>
&gt;&gt; &gt;&gt; &gt; little.<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; Such a missing feature tickles me from time to time, and I often<br>
&gt;&gt; &gt;&gt; &gt; &gt; find<br>
&gt;&gt; &gt;&gt; &gt; &gt; that<br>
&gt;&gt; &gt;&gt; &gt; Racket `values&#39; system is too cumbersome to be used more often, i.e.,<br>
&gt;&gt; &gt;&gt; &gt; you need<br>
&gt;&gt; &gt;&gt; &gt; to go through stages of `call-with-values&#39;, &#39;let/define-values&#39;,<br>
&gt;&gt; &gt;&gt; &gt; `(apply<br>
&gt;&gt; &gt;&gt; &gt; values<br>
&gt;&gt; &gt;&gt; &gt; ....)&#39;, etc. and I often find myself not wanting to go down this<br>
&gt;&gt; &gt;&gt; &gt; road.<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; IMO, `values&#39; is *meant* to be the way I describe above: `values&#39;<br>
&gt;&gt; &gt;&gt; &gt; &gt; is<br>
&gt;&gt; &gt;&gt; &gt; &gt; exactly<br>
&gt;&gt; &gt;&gt; &gt; like `list&#39;, except than instead of encapsulating the values in a<br>
&gt;&gt; &gt;&gt; &gt; container, it<br>
&gt;&gt; &gt;&gt; &gt; splices them in-place.<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; Do you see some disadvantages of using values this way?<br>
&gt;&gt; &gt;&gt; &gt; &gt; For example, in some occasions, for things like<br>
&gt;&gt; &gt;&gt; &gt; &gt; (define (foo x) (values x x))<br>
&gt;&gt; &gt;&gt; &gt; &gt; (map + (foo &#39;(1 2 3)))<br>
&gt;&gt; &gt;&gt; &gt; &gt; it may be more difficult to infer that there are actually 2 lists<br>
&gt;&gt; &gt;&gt; &gt; &gt; in<br>
&gt;&gt; &gt;&gt; &gt; &gt; the map,<br>
&gt;&gt; &gt;&gt; &gt; but to me it&#39;s just a matter of style/taste/comments/documentation,<br>
&gt;&gt; &gt;&gt; &gt; not<br>
&gt;&gt; &gt;&gt; &gt; a<br>
&gt;&gt; &gt;&gt; &gt; matter of feature.<br>
&gt;&gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; &gt; Laurent<br>
&gt;&gt; &gt;&gt; &gt; &gt; ____________________<br>
&gt;&gt; &gt;&gt; &gt; &gt;  Racket Users list:<br>
&gt;&gt; &gt;&gt; &gt; &gt;  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; ------------------------------------------------------------------------------<br>
&gt;&gt; &gt;&gt; &gt; [application/pkcs7-signature &quot;smime.p7s&quot;] [~/Desktop &amp; open] [~/Temp<br>
&gt;&gt; &gt;&gt; &gt; &amp;<br>
&gt;&gt; &gt;&gt; &gt; open]<br>
&gt;&gt; &gt;&gt; &gt; ____________________<br>
&gt;&gt; &gt;&gt; &gt;   Racket Users list:<br>
&gt;&gt; &gt;&gt; &gt;   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ____________________<br>
&gt;&gt; &gt;   Racket Users list:<br>
&gt;&gt; &gt;   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>&gt;<br>
&gt;&gt; Assistant Professor / Brigham Young University<br>
&gt;&gt; <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
&gt;&gt;<br>
&gt;&gt; &quot;The glory of God is Intelligence&quot; - D&amp;C 93<br>
&gt;&gt; ____________________<br>
&gt;&gt;   Racket Users list:<br>
&gt;&gt;   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
<br>
<br>
--<br>
Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>&gt;<br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
&quot;The glory of God is Intelligence&quot; - D&amp;C 93<br>
</div></div></blockquote></div><br></div>