Re: Pass by Reference

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

..... I usually start with the opposite question: why should I force other people to learn a new syntax? It's not that should never happen, but all things being equal, there should be a good reason for doing so.

I apologize for being "late to the party" on this, but consider the two options:

function foo() 
   return 1, 2, 3, 4 
end function 
 
a, b, c = foo() 

vs.

function foo() 
   return {1, 2, 3} 
end function 
 
{a, b, c, d} = foo() 

Obviously, the first can be verified as incorrect by the parser.

The second can only be determined to be wrong at runtime, and will result in a crash.

Unlike indexes, there's no way to check for this error - you can't see how many values a function is returning. So the use of this syntax is intrinsically unsafe, and there's no way that I see to make it safe.

Am I missing something here?

- David

First of all Euphoria is promoted as a language that handles sequences. At the time of its original implementation there were very few languages addressing the problem of manipulating and working on sequences and Euphoria and APL were notable exceptions. So the sequence handling ability and emphasis of Euphoria should be emphasised to the newcomer so he knows he is undertaking an excursion into manipulating sequence and he chooses euphoria with open Eyes.
Then it becomes obvious that he should not be encouraged (in the examples he can access) or in the manual to

  return 1, 2, 3, 4 

and do instead

     retvar = 1, 2, 3, 4 
  return retvar 

The next statement or function that wants to use retvar will be forced to look at its size. (BTW retvar would be previously defined as a sequence that would eventually be available.) In any case somebody else has already answered David Cuny that Euphoria allows a mismatch in size of sequence or number of variables by dropping a value or a varname.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu