On Thu, 15 Dec 2011, Zayr Okale wrote: > I even do understand what multiple return values are useful for in CL: "okay, > the function calculates other potentially useful values anyway, so no reason > not to make them available". > > Unfortunately, this scenario doesn't apply to Racket. And this is exactly what > prompted my question. Since one of the reasons behind multiple return values > is, as David Van Horn pointed out, symmetry with multiple input values > (function arguments), then why optional input values are allowed, but optional > output values aren't?
This question is probably better asked to people behind RnRS. I was unable to give you any interesting examples with Scheme, because I didn't know them. Actually, I was a bit unsure about this multiple values stuff myself, as I had been reading R5RS some time ago (I am yet to find time for R6RS, so maybe there is more about values, but I don't know right now). After I exchanged punches with CL, I've got a bit better understanding of the issue. Or so I hope. Your question sounded like one of more general nature, which is why I allowed myself to do this CL/C intrusion here. > The situation when all the return values are of equal importance, yet > returning a struct or a list is not convenient is, IMHO, quite rare. I don't want to bet on this :-) . I think that in some cases you may emulate values by operating on list. Like, return a list of values and later use apply. However, once you have to produce list of specified size, it becomes inconvenient, IMHO. Because no matter what you want, you have to make this one specific list and later go through it to access the elements (this can be optimized, but one shouldn't count on such happy end). So I think using list/struct forces an overhead when later you want to make use of the values. On the other hand, with values (again, sorry for CL), one can have: [2]> (multiple-value-bind (f r) (floor 130 11) (list f r)) (11 9) This is from CL HyperSpec. Here, your data is "inserted" into your namespace, and this can be paired with (declare (ignore ...)) to make it perform better. Situations like this can be rare in other languages, simply because for mul-vals to work and make sense it requires a bit bigger ecosystem of language constructs and, like above, assumption about how and where things are going to be optimized. Above, I think the minimal approach would be to analyze entire multiple-value-bind expression. I keep an eye on Racket but I don't know it too well (just one non-trivial program bettered with profiler and few smaller ad hoc pieces over few years period), so I am unsure how much sense is there in using values in it. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_r...@bigfoot.com ** _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users