Re: Pass by Reference
- Posted by petelomax Jan 13, 2015
- 2272 views
Hmmm. Just some random thoughts:
There is a limit to how far you can or should mollycoddle the developer, but let's not get into a fight over that.
Not all functions return a fixed number/length of results. Some, of course, return an integer on error and a sequence on success.
One thing about
s = foo() {x,y,z} = s
is that it can give extra debugging info.
If we say s = foo() generates an error, what about {s} = {foo()} and s = {fee(),foo()} and g(foo()) and return foo() and... ?
OpenEuphoria (wrongly, imo) also allows foo(), ie implicit discard of all results, without any warning. In Phix I use {} = foo() as the explicit discard.
Regarding extra decorations on function definitions, may I suggest:
function f() with multiple_returns
or
function f() with forced_desequence
or
return[2] {new,old} end function
or even
return[2..8] <result built with append etc> end function
any of which means there would be no extra errors or warnings for any legacy code, a definite plus point.
FYI, Phix (already) currently does this:
function f2() return {1,2} end function integer a -- a = f2() -- ^ type error (storing sequence in atom)
Needless to say, Phix already deduces function return types and therefore I am not as keen on explicit return types as some might be.
Were those thoughts random enough for you?
Pete