|
Nude posted:Something must of went over my head here; any reason why returning arrays would not be a solution? Sample code. Because that doesn't let you return values of different types, and the compiler won't save you from trying to extract too many or too few values from the return value.
|
# ? Jun 19, 2016 07:32 |
|
|
# ? Jun 8, 2024 07:00 |
Lua's multiple return is very weird yes. Values you don't capture with an assignment are lost, unless you wrap the function call in an array constructor or another function call. If you wrap it with an array constructor you obviously (?) get an array of the returned values, and if you wrap it in another function call then the returned values are used as sequential arguments to that call! But if you wrap the function call returning multiple values in parentheses then you truncate the result to one value again. Definitely irregular and a source of many potential gotchas. code:
nielsm fucked around with this message at 07:45 on Jun 19, 2016 |
|
# ? Jun 19, 2016 07:40 |
|
Apparently multiple return values got into CL from Lisp Machine Lisp. Steele and Gabriel's Evolution of Lisp has Section 3.5.2 Generalized Multiple Values which begins, quote:Many Lisp extenders have independently gone down the following path. Sometimes it is desirable to return more than one item from a function. It is awkward to return some of the results through global variables, and inefficient to cons up a list of the results (pushing the system that much closer to its next garbage collection) when we know perfectly well that they could be returned in machine registers or pushed onto the machine control stack. Another point that mentioned was that putting the auxiliary value in a global is worse. And here's the Lisp Machine Lisp Manual section on multiple values which has some starry-eyed talk of loose guarantees helping out some optimizing compiler.
|
# ? Jun 19, 2016 08:16 |
|
The 1983 Interlisp Reference Manual has a section on a feature called "DWIM."quote:However, it is important to note that even when DWIM is wrong, no harm is done:2 since an error had occurred, the user would have had to intervene anyway if DWIM took no action. Guess what that's about. Automatic run-time spell-checking. The footnote: quote:2Except perhaps if DWIM's correction mistakenly caused a destructive computation to be initiated, and information was lost before the user could interrupt. We have not yet had such an incident occur. An ominous out-of-context quote: quote:The variable DWIMUSERFORMS provides a convenient way of adding to the transformations that DWIM performs. I think this has some great ideas that I should share with the swift-evolution mailing list.
|
# ? Jun 19, 2016 08:42 |
|
weird posted:are there any languages other than lisp that do swift
|
# ? Jun 19, 2016 11:43 |
|
Dwim was a thing in lots of compilers, especially in education, in the batch punch card days because of turnaround times - waiting a day to recompile because of a typo sucks. These days more dangerous than useful.
|
# ? Jun 19, 2016 12:27 |
|
In Forth, having operations consume and produce multiple results is extremely natural and such operations compose well. I agree that you cannot simply bolt a feature like multiple return into an existing language and have it work well, but there's a huge design space outside "essentially ALGOL with some keywords changed around". Live a little.
|
# ? Jun 19, 2016 15:03 |
|
Nude posted:Something must of went over my head here; any reason why returning arrays would not be a solution? Sample code. I guess I'm just trying to wrap my head around a concept of returning multiple values, but not considered an array/object and why someone would want that. In addition to the issues that vOv pointed out (some of which can be solved using c#'s "tuples"), it's also just annoying enough that I'd rather use out. If I want to get the values into local variables I need two lines of code after the function call to copy the values out into those variables. Compare that to the destructuring tuples in other languages where it all happens on a single line. Anyway it looks like c#7 might be getting proper tuple destructuring which would be cool.
|
# ? Jun 19, 2016 16:05 |
|
Multiple return values are certainly perfectly natural with a stack-based language. The reason why they're so weird in Lua is that the API is stack-based and it's straightforward to have a function you call pop off three arguments and push two return values, but the actual language is expression-based.
|
# ? Jun 19, 2016 16:06 |
|
HappyHippo posted:In addition to the issues that vOv pointed out (some of which can be solved using c#'s "tuples"), it's also just annoying enough that I'd rather use out. If I want to get the values into local variables I need two lines of code after the function call to copy the values out into those variables. Compare that to the destructuring tuples in other languages where it all happens on a single line. Does c# not have an equivalent to the C++ tie?
|
# ? Jun 19, 2016 16:17 |
|
HappyHippo posted:In addition to the issues that vOv pointed out (some of which can be solved using c#'s "tuples"), it's also just annoying enough that I'd rather use out. If I want to get the values into local variables I need two lines of code after the function call to copy the values out into those variables. Compare that to the destructuring tuples in other languages where it all happens on a single line. Something like this? code:
code:
|
# ? Jun 19, 2016 17:22 |
|
go allows multiple returns which it implements internally as a tuple (or something it calls a tuple) but it doesn't actually have a tuple data type. It's sort of weird -- you can use an expression with multiple returns as the sole argument of another function with multiple arguments as long as the type signatures match. But you cant assign the result of a multiple return expression to a singular (tuple) value. It's got to be one of those intentional 'simplicity' designs because I cannot imagine designing a language with multiple return values and not go hog wild with destructuring syntax.
|
# ? Jun 19, 2016 17:48 |
|
MALE SHOEGAZE posted:It's got to be one of those intentional 'simplicity' designs because I cannot imagine designing a language with multiple return values and not go hog wild with destructuring syntax. Case in point: Ceylon.
|
# ? Jun 19, 2016 18:45 |
|
MALE SHOEGAZE posted:It's got to be one of those intentional 'simplicity' designs because I cannot imagine designing a language with multiple return values and not go hog wild with destructuring syntax. go in a nutshell
|
# ? Jun 19, 2016 18:45 |
HappyHippo posted:It's usually pattern matching with tuples. I guess it's not technically multiple return values but it's close enough And C++! C++ code:
|
|
# ? Jun 19, 2016 21:03 |
|
Of course C++ manages to do it in the ugliest way possible.
|
# ? Jun 19, 2016 22:10 |
HappyHippo posted:Of course C++ manages to do it in the ugliest way possible. Return type deduction ought to work for it, actually. C++ code:
E: You can use "auto" for the return values to get a packed tuple, but accessing the elements is ugly then, with std::get<index>(tuple). nielsm fucked around with this message at 22:22 on Jun 19, 2016 |
|
# ? Jun 19, 2016 22:17 |
nielsm posted:Return type deduction ought to work for it, actually. Also I think foo() in your example returns a const char[] instead of a std::string. Not sure if that's better or not; probably depends on the scenario. VikingofRock fucked around with this message at 00:32 on Jun 20, 2016 |
|
# ? Jun 20, 2016 00:28 |
|
VikingofRock posted:Also I think foo() in your example returns a const char[] instead of a std::string. Not sure if that's better or not; probably depends on the scenario. const char*
|
# ? Jun 20, 2016 00:53 |
leper khan posted:const char* Whoops. Yeah that.
|
|
# ? Jun 20, 2016 02:28 |
|
The best part about c++ is that anytime anyone talks about it or answers a question, three more people pop up to say "yes but..." or otherwise clarify the answer. Because it's probably the most byzantine language ever created.
|
# ? Jun 20, 2016 04:50 |
|
HappyHippo posted:The best part about c++ is that anytime anyone talks about it or answers a question, three more people pop up to say "yes but..." or otherwise clarify the answer. Because it's probably the most byzantine language ever created. Is that really only a thing for C++? I look up a lot of Java stuff on StackOverflow and more often than not people suggest a few alternative options.
|
# ? Jun 20, 2016 07:42 |
|
Carbon dioxide posted:Is that really only a thing for C++? I look up a lot of Java stuff on StackOverflow and more often than not people suggest a few alternative options. It's not so much options as clarifications. Like what we just saw, where someone used auto for a function that originally returned a std::string, then the next poster pointed out that auto would actually resolve as const char[], then the next poster pointed out that it actually resolves as const char* (which is subtly different). It's just something I've noticed whenever people talk about c++ that doesn't seem to happen nearly as much with other languages.
|
# ? Jun 20, 2016 15:34 |
HappyHippo posted:it's probably the most byzantine language ever created. I love this description of C++. C was already a subtle language full of edge cases, and C++ turned that up to 11. For example, here is another weird subtlety related to that code snippet: Usually you can pretty much think of strings as really just being arrays of chars, and arrays as really being special syntax for pointers to their first element. But this isn't always the case. Consider these two functions: C++ code:
Disclaimer: I probably made a few subtle errors in this post, and people should feel free to jump in and correct me.
|
|
# ? Jun 20, 2016 19:58 |
|
VikingofRock posted:I love this description of C++. C was already a subtle language full of edge cases, and C++ turned that up to 11. I think you meant x11
|
# ? Jun 20, 2016 20:52 |
|
Edison was a dick posted:Does c# not have an equivalent to the C++ tie? Nope. There was going to be syntax for declaring out parameters at call sites, but it didn't make into C# 6.0.
|
# ? Jun 20, 2016 21:11 |
|
Error restarting /my-app: [Object object] Never ceases to be funny.
|
# ? Jun 21, 2016 00:45 |
|
VikingofRock posted:I love this description of C++. C was already a subtle language full of edge cases, and C++ turned that up to 11. For example, here is another weird subtlety related to that code snippet: The best part is that if you do C++ for long enough, it'll all seem perfectly normal and straightforward. "Of course it makes sense for the type of this template parameter to be deduced as char const[69]! Why would you expect it to be deduced as char const*? Oh, well, yeah, in that other case that looks similar of course it's deduced as char const*, I mean, duh."
|
# ? Jun 21, 2016 01:52 |
|
HappyHippo posted:Because it's probably the most byzantine language ever created. Ottoman, Byzantine was deprecated a while ago.
|
# ? Jun 21, 2016 05:35 |
|
HappyHippo posted:Because it's probably the most byzantine language ever created. Verity Stob posted:Whereas smaller computer languages have features designed into them, C++ is unusual in having a whole swathe of functionality discovered, like a tract of 19th century Africa.
|
# ? Jun 21, 2016 05:45 |
|
I can't print a PDF in Windows 10 in any program (Sumatra, Foxit, Acrobat, Edge, Firefox, Chrome) without the program running as administrator. Any other file works fine.
|
# ? Jun 21, 2016 22:16 |
|
aren't pdf's executables that need to run as admin
|
# ? Jun 21, 2016 22:22 |
|
No loving way am I opening a PDF as admin.
|
# ? Jun 22, 2016 00:05 |
|
If I had a time machine, the second thing after killing Hitler would be telling the Postscript development team that the only people who want a Turing complete print format are hackers and the people who think it's cute to poo poo up the office printer for an hour while it dynamically computes an arbitrarily zoomed portion of the Mandelbrot set.
|
# ? Jun 22, 2016 04:12 |
|
PDF removed the Turing completeness. And then added it back in the form of JavaScript and Flash.
|
# ? Jun 22, 2016 04:14 |
|
doesn't pdf literally support a /Launch directive to spawn other binaries too
|
# ? Jun 22, 2016 04:20 |
|
http://www.youtube.com/watch?v=54XYqsf4JEY This video is always great.
|
# ? Jun 22, 2016 05:19 |
|
Your future coding horror: making sure your Python code is Unicode 9.0-compatible.
|
# ? Jun 22, 2016 05:28 |
|
Biowarfare posted:doesn't pdf literally support a Yes.
|
# ? Jun 22, 2016 05:40 |
|
|
# ? Jun 8, 2024 07:00 |
|
1337JiveTurkey posted:If I had a time machine, the second thing after killing Hitler would be telling the Postscript development team that the only people who want a Turing complete print format are hackers and the people who think it's cute to poo poo up the office printer for an hour while it dynamically computes an arbitrarily zoomed portion of the Mandelbrot set. You can trick a lot of printers into dumping their ps stacks too, so you can do more than just line art dicks...
|
# ? Jun 22, 2016 08:45 |