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