$ 6 'BEGIN my $x = 42; my @a is default($x); say @a[1]'
42

It’s all a matter of needing a compile time value.

$ 6 'constant $x = 42; my @a is default($x); say @a[1]'
42

Is another way of doing this.


I’m not sure how we can actually fix the reported case, without breaking the 
above cases.  If we really want a more flexible default value, then maybe we 
should allow a Callable as a default value.  And call that whenever we need to 
revert to the default value?

> On 09 Aug 2016, at 23:53, Aleks-Daniel Jakimenko-Aleksejev (via RT) 
> <perl6-bugs-follo...@perl.org> wrote:
> 
> # New Ticket Created by  Aleks-Daniel Jakimenko-Aleksejev 
> # Please include the string:  [perl #128879]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=128879 >
> 
> 
> Code:
> my $x = 42;
> my @a is default($x);
> say @a[1]
> 
> Result:
> (Any)
> 
> 
> It is doc-ed correctly, so one might argue that the user should've known
> better. But it is very LTA, and if there is a way to warn the user (or why
> warn, let's make it a compile-time error?) then we should definitely do it.

Reply via email to