Re: Basic question about lexical binding in relationship with "list assignment"

2019-01-02 Thread Elizabeth Mattijsen
Fixed with https://github.com/rakudo/rakudo/commit/23663609a7

> On 27 Dec 2018, at 09:29, Raymond Dresens  wrote:
> 
> Hello,
> 
> I'm getting up to speed with Perl 6 again after a long while, and I more
> or less 'hit my nose' against something that I can reduce to the
> following very basic snippet of code:
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my $foo = 6;
> 
>say $foo;
>}
> 
> This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
> '$foo' is already bound to an outer symbol; the implicit outer binding
> must be rewritten as OUTER::<$foo> before you can unambiguously declare
> a new '$foo' in this scope.
> 
> This will compile with Perl 5 when I add 'use v5.14;' at the top and it
> will then print 3, then 3 then 6 (as expected).
> 
> Well, it seems that I can 'cheat' by simply doing a list assignment:
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my ($foo) = 6; # avoid `... '$foo' is already bound ...'
> 
>say $foo;
>say $foo.WHAT; # is it really an integer?
>}
> 
> The output is:
> 
>3
>(Any)
>6
>(Int)
> 
> This behavior is fine I think (but a little unexpected due to my
> experience with Perl 5).
> 
> Is this behavior normal/wanted/intented (from a language/compiler
> perspective?).
> 
> Perhaps this shouldn't be and the compiler should also complain in this
> list assignment case, or perhaps generate a warning?
> 
> I'm not that confident to state that this is a bug ;)
> 
> Hence the reason why I kind-of report this,
> 
> I hope this is somewhat useful,
> 
> Thanks for your time,
> 
> Regards,
> 
> Raymond Dresens.


Re: Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread Elizabeth Mattijsen
I’d say it is a bug you do not get the error with “my ($foo) = 6”, as clearly 
the first “say $foo” inside the scope is referring to the inner $foo, not the 
outer $foo.  So I’d suggest filing an issue for that: 
https://github.com/rakudo/rakudo/issues

> On 27 Dec 2018, at 09:29, Raymond Dresens  wrote:
> 
> Hello,
> 
> I'm getting up to speed with Perl 6 again after a long while, and I more
> or less 'hit my nose' against something that I can reduce to the
> following very basic snippet of code
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my $foo = 6;
> 
>say $foo;
>}
> 
> This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
> '$foo' is already bound to an outer symbol; the implicit outer binding
> must be rewritten as OUTER::<$foo> before you can unambiguously declare
> a new '$foo' in this scope.
> 
> This will compile with Perl 5 when I add 'use v5.14;' at the top and it
> will then print 3, then 3 then 6 (as expected).
> 
> Well, it seems that I can 'cheat' by simply doing a list assignment:
> 
>my $foo = 3;
>say $foo;
> 
>{
>say $foo;
> 
>my ($foo) = 6; # avoid `... '$foo' is already bound ...'
> 
>say $foo;
>say $foo.WHAT; # is it really an integer?
>}
> 
> The output is:
> 
>3
>(Any)
>6
>(Int)
> 
> This behavior is fine I think (but a little unexpected due to my
> experience with Perl 5).
> 
> Is this behavior normal/wanted/intented (from a language/compiler
> perspective?).
> 
> Perhaps this shouldn't be and the compiler should also complain in this
> list assignment case, or perhaps generate a warning?
> 
> I'm not that confident to state that this is a bug ;)
> 
> Hence the reason why I kind-of report this,
> 
> I hope this is somewhat useful,
> 
> Thanks for your time,
> 
> Regards,
> 
> Raymond Dresens.


Re: Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread JJ Merelo
Hi,

El jue., 27 dic. 2018 a las 9:30, Raymond Dresens (<
raymond.dres...@gmail.com>) escribió:

> Hello,
>
> I'm getting up to speed with Perl 6 again after a long while, and I more
> or less 'hit my nose' against something that I can reduce to the
> following very basic snippet of code:
>
> my $foo = 3;
> say $foo;
>
> {
> say $foo;
>
> my $foo = 6;
>
> say $foo;
> }
>
> This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
> '$foo' is already bound to an outer symbol; the implicit outer binding
> must be rewritten as OUTER::<$foo> before you can unambiguously declare
> a new '$foo' in this scope.
>

But where's that error? In the first "say $foo"?

>
> This will compile with Perl 5 when I add 'use v5.14;' at the top and it
> will then print 3, then 3 then 6 (as expected).
>
> Well, it seems that I can 'cheat' by simply doing a list assignment:
>
> my $foo = 3;
> say $foo;
>
> {
> say $foo;
>
> my ($foo) = 6; # avoid `... '$foo' is already bound ...'
>

That should make no difference...

>
> say $foo;
> say $foo.WHAT; # is it really an integer?
> }
>
> The output is:
>
> 3
> (Any)
>

That's the first say $foo in the block, I guess...

6
> (Int)
>
> This behavior is fine I think (but a little unexpected due to my
> experience with Perl 5).
>
> Is this behavior normal/wanted/intented (from a language/compiler
> perspective?).
>
> Perhaps this shouldn't be and the compiler should also complain in this
> list assignment case, or perhaps generate a warning?
>
> I'm not that confident to state that this is a bug ;)
>
> Hence the reason why I kind-of report this,
>


It might be a documentation bug... Which you might want to report anyway.
The thing with Perl 6 is that parsing, compiling and runtime are quite
different. In Perl, far as I can tell, you are actually assigning scope to
$foo when you run that sentence. That's not the case in Perl 6, or does not
seem to be. However, this should be quite clear from the get go.

Cheers

JJ


Basic question about lexical binding in relationship with "list assignment"

2018-12-27 Thread Raymond Dresens
Hello,

I'm getting up to speed with Perl 6 again after a long while, and I more
or less 'hit my nose' against something that I can reduce to the
following very basic snippet of code:

my $foo = 3;
say $foo;

{
say $foo;

my $foo = 6;

say $foo;
}

This will not compile with Perl 6 (Rakudo 2018.12) -- lexical symbol
'$foo' is already bound to an outer symbol; the implicit outer binding
must be rewritten as OUTER::<$foo> before you can unambiguously declare
a new '$foo' in this scope.

This will compile with Perl 5 when I add 'use v5.14;' at the top and it
will then print 3, then 3 then 6 (as expected).

Well, it seems that I can 'cheat' by simply doing a list assignment:

my $foo = 3;
say $foo;

{
say $foo;

my ($foo) = 6; # avoid `... '$foo' is already bound ...'

say $foo;
say $foo.WHAT; # is it really an integer?
}

The output is:

3
(Any)
6
(Int)

This behavior is fine I think (but a little unexpected due to my
experience with Perl 5).

Is this behavior normal/wanted/intented (from a language/compiler
perspective?).

Perhaps this shouldn't be and the compiler should also complain in this
list assignment case, or perhaps generate a warning?

I'm not that confident to state that this is a bug ;)

Hence the reason why I kind-of report this,

I hope this is somewhat useful,

Thanks for your time,

Regards,

Raymond Dresens.