Skip to content

Instantly share code, notes, and snippets.

@skids
Last active August 29, 2015 14:23
Show Gist options
  • Save skids/5d7a9cdd20bf6c303eb6 to your computer and use it in GitHub Desktop.
Save skids/5d7a9cdd20bf6c303eb6 to your computer and use it in GitHub Desktop.
Further investigation of RT#117043.
Further investigation of RT#117043.
1) It is specced (via STD and from there RT#116607 and from there
S32-exceptions/misc.t) that sigilless my variables must have an
initializer. I could not find an explanation as to why.
$ perl6 -e 'my (\a);' # no error
$ perl6 -e 'my \a;' # intended error
===SORRY!=== Error while compiling -e
Term definition requires an initializer
at -e:1
------> my \a⏏;
2) Whether this principle carries over to sigilless parameters
is hard to discern.
std: sub (\a?) { }
std 28329a7: OUTPUT«===SORRY!===␤Unable to parse signature at /tmp/866RutNr2q line 1:␤------> sub ⏏(\a?) { }␤Couldn't find final ')'; gave up at /tmp/866RutNr2q »
$ perl6 -e 'sub (\a?) { }' # Either LTA error, or broken
===SORRY!=== Error while compiling -e
Missing block
at -e:1
------> sub (\a⏏?) { }
3) Sigilless variables in general are apparently supposed to
just bind, when "assigned." No spectests seem to try to write
to them.
$ perl6 -e 'my \a = 1; a = 2'
Cannot modify an immutable Int
in block <unit> at -e:1
$ perl6 -e 'sub f (\a is copy) { a = 6; a.say }; f(5)' # Seems to be equivalent
Cannot modify an immutable Int
in sub f at -e:1
in block <unit> at -e:1
$ perl6 -e 'my $b = 4; my \a = $b; $b = 2; a.perl.say;' # Further evidence
2
$ perl6 -e 'my \a = (); a = 3; a.perl.say;' # This is odd
()
$ my \a := (); a = 3; a.perl.say;' # Same thing this way
()
$ perl6 -e 'my $a := (); $a = 3; $a.perl.say;' # Expected behavior
Cannot assign to an immutable value
in block <unit> at -e:1
4) Precedence (?) for behavior when a bind does not happen but a
declaration does:
$ perl6 -e 'my ($a, $b?) := 1,; $b.perl.say'
Mu
5) In any case if '=' means "bind" for sigilless variables,
then any mixture of sigiled and sigilless variables like:
my ($a, \b) = 3,4;
... means that the signature has to be iterated and the operation
(bind or assign) chosen based on whether the variable is sigilless
or not.
Internally this:
my (\x1) = 4;
...currently gets routed to a p6store:
- QAST::Op(p6store) (\\x1) = 4
- QAST::Op(call &infix:<,>)
- QAST::Var(lexical x1 :decl())
- QAST::Want 4
- QAST::WVal(Int)
- Ii
- QAST::IVal(4)
...and so this probably unintended behavior is possible:
$ perl6 -e 'my (\a) = 4; a.say; a = 5; a.say;'
(Any)
5
6) The list-declarator construct also admits this:
my (\c, \d) = @runtime-valued-array;
...which, if mandatory initialization is desired, must fail at
runtime based on the @runtime-valued-array.elems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment