New things are not l-values --- I just tried this and the compiler agrees.

AFAICT the only way you can currently give ref parameters default values is
something along these lines:

var err = new errorstate();
proc foo(ref err = err) { ... }

To use C parlance, this is taking a reference to a global variable, whereas
we want to create a reference to an automatic variable in the call stack.
Unless I'm missing something, you can't currently do this.

The syntax I proposed "ref x? : errorstate" then translates as "if x is
given, use that, if not then create a new variable of type errorstate in
the call stack and let x be a reference to that". And "ref x? = new
errorstate()" would translate as "if x is given, use that, if not then
create a new variable with value new errorstate() and let x be a reference
to that."

Even more simply, the question mark means "create a new automatic variable
if you have to".

Chris



On 6 December 2013 22:17, Brad Chamberlain <[email protected]> wrote:

>
>  Hi Brad,
>>
>> (3) is a very good point. While I don't see (1) and (2) as a major
>> objection, they do point out that for "undefined" to be useful in the
>> common case, an undefined variable should be assignable.  This essentially
>> means that a variable may have two values (it's actual value and
>> "undefined") which is absurd so I'll concede.
>>
>> As it stands, if you want to be able to omit an argument to a function
>> then
>> it needs to be given a default value.  This does not help much with my
>> motivating example (error propagation) because the error state must be
>> passed by reference, and so the default variable must be an lvalue.
>>
>
> Rather than changing the language, how about simply doing:
>
>         proc foo(ref err = new errorstate());
>
> This gives you the l-value you want, in a task-safe manner, and also
> addresses the issue of requiring a type to be specified?
>
> -Brad
>
------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to