On Monday, 12 January 2015 at 21:11:44 UTC, Walter Bright wrote:
On 1/12/2015 6:57 AM, Martin Nowak wrote:
The general solution in functional programming is error
chaining.
An example, C is a function that reads in lines of a program
and B is a function
that takes all those lines and counts words.
C will either return an error or lines and B will either
immediately return that
error to A or convert the lines to word counts.
This works especially well with function chaining, because you
can hide the
error propagation in a generic chaining method (called map).
http://danielwestheide.com/blog/2012/12/26/the-neophytes-guide-to-scala-part-6-error-handling-with-try.html
Yes, it still appears to be just a wrapper around returning two
values, and that has to be done for everything.
Yes, you wrap the return values, but it doesn't require to deal
with errors in B.
There's another downside to returning two values - extra code
is generated, and it consumes another register. It allocates
very scarce resources to rare cases - not a recipe for high
performance.
To defend that argument we'd first have to fix our own codegen.
https://issues.dlang.org/show_bug.cgi?id=12442
It doesn't really consume the register, because the error value
is only needed directly after the call for a possible early
return. But of course returning tuples can be less efficient.
OT!!
Reminds me of Manu's request for more efficient register return.
www.digitalmars.com/d/archives/digitalmars/D/Multiple_return_values..._160353.html