On 7/8/19 9:44 PM,
lgo...@gmail.com wrote:
> f( g() ) compiles when g returns exactly the number of args that f()
> requires, but if g() returns only 1/2 that number f (g(), g() ) wont
> compile !! ...Is this not a Golang absurdity ??
On the contrary, it's a good example of Go's pragmatism, allowing some
relatively safe syntactic sugar without opening a Pandora's box of
complete generality.
To illustrate Rob Griesemer's point, in his comment that I linked to in
my earlier reply
(
https://github.com/golang/go/issues/973#issuecomment-142733515),
consider the following package that's maintained by someone else (your
colleague or an Internet stranger):
===
package mu
func CalcDispersion (in []float64) (variance float64, stddev float64) {
... }
func CalcAvg (in []float64) (sma21 float64, ema21 float64) { ... }
===
Then you use it as follows, assuming a future Go version that allows
"spreading" of multi-valued function returns:
===
v, sd := mu.CalcDispersion(i)
sma, ema := mu.CalcAvg(i)
func delta (a, b float64) float64 { return a-b }
d1 := delta(mu.CalcDispersion(i))
d2 := delta(mu.CalcAvg(i))
func me (variance float64, stddev float64, sma21 float64, ema21 float64)
float64 { ... }
m := me(mu.Alpha(i), mu.Beta(i))
===
All well and fine, until one day, the package interface changes after
some discussion:
===
package mu
func CalcDispersion (in []float64) (variance float64, stddev float64,
range float64) { ... }
func CalcAvg (in []float64) (sma21 float64) { ... }
===
Yes, that's a breaking change, and the Go compiler helpfully screams at
you on every assignment statement ...except the last one. And since the
compiler was silent about that last line, you're almost certainly gonna
miss the HUGE logic error in it...and spend days scratching your head at
the absurd results your program throws up.
--
Best Regards,
Adrian