Re: Pass by Reference
- Posted by ghaberek (admin) Jan 13, 2015
- 2226 views
jimcbrown said...
You're right - it is easier to just have the developer specify intent and let the parser enforce it. But I think we can still keep it within desequencing:
function foo(sequence this, integer update_value) integer prior_value = this[1] this[1] = update_value return using desequencing with size 2 values {this, prior_value} -- we can come up with a better syntax than this end function object spare sequence this = {50} this = foo(this, 11) -- parser blows up here since we aren't using desequencing, but we stated that we intended the caller of this function must use it. {this} = foo(this, 11) -- parser blows up here since it can tell that there's a size mismatch {this, ?} = foo(this, 11) -- parser allows this {this, spare} = foo(this, 11) -- parser allows this
It seems like this might be a better syntax.
function foo(sequence this, integer update_value) integer prior_value = this[1] this[1] = update_value return (2){this, prior_value} end function
It can be read aloud as "return two values, this and prior_value."
-Greg