Re: Pass by Reference
- Posted by mattlewis (admin) Jan 13, 2015
- 2378 views
there's a strong mapping between the use of commas in the return and the assignment:
function foo() return 1, 2, 3 end function a, b, c = foo()
By adding this syntax to Euphoria, you're no longer emulating the behavior, and you get the full benefit: the parser can catch logical errors because it sees what was written didn't follow the intent.
I think I'd like there to be something else when returning like this to highlight that something different is happening. Maybe square brackets:
function foo() return [1, 2, 3] end function [a, b, c] = foo()
Some additional wrinkles. At first glance, I don't see an obvious way to use such a function in an expression or as an argument for another function. Obviously, returning a sequence means the user needs to know what's coming. This isn't necessarily a deal breaker. Though maybe this is where we add subscripting and slicing for literals / expressions:
function foo() return [1, 2, 3] end function ? foo()[1..2] -- { 1, 2 }
This is maybe a little confusing, since it sort of duplicates the existing de-sequence operator for LHS expressions.
Matt