3 ms·
For a moment, I thought they had added true multiple value return to C++. I am sooo glad they didn't. The lisp folks added it way back, and it has been an ugly
by qwertyuiop924 11y ago
For a moment, I thought they had added true multiple value return to C++. I am sooo glad they didn't. The lisp folks added it way back, and it has been an ugly scar on the language ever since. Why do real multi-value returns suck? because they don't compose well, they're awkward as all heck to use, and require wrapping certain function calls in really weird constructs. The PROPER way to do multiple values is to return a data structure and pattern match against it. Of course, lisp has support for this, multi-value return was just an optimization hack. WHICH YOU SHOULD NO LONGER USE!
- masklinn 11y agoIt's funny, your comment uses "true MRV" for language-level special-casing by opposition to a matched (or even just python-style unpacked) data-structure, whereas I've always thought the latter was "true MRV". Either way, we do agree on MRV being a language-level special case being a hack. Even PHP isn't that bad — though the unpacking is macro-ish bleh.
- junke 11y agoIf you wrap your data in a list or a tuple, it is still a single value. It makes sense to talk about true MRV in languages that support it, like Ada, Forth and others... (https://rosettacode.org/wiki/Return_multiple_values https://rosettacode.org/wiki/Return_multiple_values)
- qwertyuiop924 11y agoExactly.
- junke 11y agoMultiple values are not "just" an optimization hack, they are designed to be convenient to use. I don't know which construct you find "weird". Multiple-value-bind is a descriptive name which is long to type but this does not matter (type m-v-b + auto-complete). Typical example: you read a line in a file. The line you get is terminated either by a newline character or by the end-of file. The implementation of read-line[1] must know if you reached end of file or not, but most of the time, you don't care about it. Sometimes, you want to know, and then you can take the secondary value (missing-newline-p). I like the fact that I can focus on the primary value without caring about other ones when I want. [1] http://clhs.lisp.se/Body/f_rd_lin.htm http://clhs.lisp.se/Body/f_rd_lin.htm
- JoeAltmaier 11y agoSounds like methods could also add special-purpose multiple values later, without impacting existing callers. Which is nice too.
- qwertyuiop924 11y agoMaybe this is different in CL, but in scheme, if you're using a procedure that returns multiple values, there is no default return, or wrapping the multiple values into a list: You have to use call-with-values, any number of srfis providing sugar, most commonly srfi-8, although 11 and 71 also exist, and without the sugar, god knows how many lambdas. EVERY. SINGLE. TIME. You want to call a function that returns multiple values.
- lispm 11y agoYou might want to learn Common Lisp BEFORE you make statements about how a feature of the language is obsolete or not.
- qwertyuiop924 11y agoI was talking about the general idea of MVR, AND how I thought is was implemented in lisp. I was wrong. This happens sometimes. And even the new explanation, I STILL don't like MVR. I think that returning a list or other data structure, or just writing two functions, is much clearer, and lends itself better to function chaining. Sure, in CL there's a default, which makes things a little better, but what if you want the other one? I don't want to write (multiple-value-bind (a b) (foo bar baz) b) all over my codebase, and the scheme equivalent is just as bad, if not worse.
- junke 11y agoYou don't have to write it all over the codebase. If you have a specific need, defmacro yourself out of your problem. Generally speaking, taking a secondary value alone feels like a bad use of MVR (it happens rarely with standard functions and most libraries). MVR are not intended to be substitute to other data-structures. As said elsewhere, you can and should use structs, classes, lists, hash-tables,... After all, why do we use multiple values instead of a single struct for functions arguments? Because in CL and other languages, unlike in Haskell, you don't want to define an ADT for all your functions or rely on currying. But if you start putting too many coupled parameters in your functions, it starts to smell fishy. Extracting a single value is easy, by the way: (nth-value 1 (foo bar baz))
- lispm 11y agoWhich is clearly nonsense. Multiple values have been extremely useful and there are several code bases in Common Lisp which make extensive use of it.
- qwertyuiop924 11y agoYes. They are useful. So is goto, so are continuations. MVR isn't the unforgivable sin that those things are, but imo, it makes your codebase uglier.
- lispm 11y agoMany Lisp programmers think different.
- qwertyuiop924 11y agoWell, I'm not many lisp programmers. I'm me. I've got an opinion that I think is reasonable, and I'm willing to hear you out. In fact, I already have, and I disagree. This isn't a problem, it's good to hear differing opinions, although you always sound a bit smug about it. But I could just be reading that in. Point is, I disagree, and your opinion is fine. 'Kay?