Re: Pass by Reference

new topic     » goto parent     » topic index » view thread      » older message » newer message
dcuny said...

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu