News for hackers. Stuff that matters.
Re:Returning multiple values from functions in C++ by qwertyuiop924 on Monday March 07, 2016 @01:09PM (#11240383)
Maybe 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.
Re:Returning multiple values from functions in C++ by lispm on Monday March 07, 2016 @02:09PM (#11240813)
You might want to learn Common Lisp BEFORE you make statements about how a feature of the language is obsolete or not.
Re:Returning multiple values from functions in C++ by qwertyuiop924 on Monday March 07, 2016 @02:57PM (#11241166)
I 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.
Re:Returning multiple values from functions in C++ by junke on Monday March 07, 2016 @03:15PM (#11241279)
You 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))
Re:Returning multiple values from functions in C++ by lispm on Monday March 07, 2016 @04:12PM (#11241724)
Why don't you take a bit of time to read about multiple values in Common Lisp?

    CL-USER 76 > (nth-value 1 (values 'a 'b 'c 'd))
    B
While you are at it, check out the feature of 'Macros' in Lisp, which allows everyone to write code to shorten this stuff. See my code in this thread for a macro which then allows you to write:

    (multiple-value-bind-some (NIL b)
       (foo bar baz)
      b)
One then can name ignored variables as NIL in the source code...
Re:Returning multiple values from functions in C++ by qwertyuiop924 on Tuesday March 08, 2016 @09:13AM (#11245289)
Good point. And very true. Still looks a bit ugly to me, but it's better than nothing, I suppose. And yes, I am aware of macros. For some reason using them in this situation didn't occur to me, so I guess I am an idiot after all.

This is actually one of the cases where syntax-rules would allow you to write something cleaner, I would guess. I like syntax rules, but everybody always seems to complain about it...