Here's a thorough investigation of the strange properties of %*ENV.

Rakudo r31926 has an %*ENV variable which claims to be of Hash type, but
which behaves very non-hashlike when you poke it. Its hash values are
supposedly strings, but don't have the corresponding Str methods.

say 'a'.WHAT;
# Str

say 'a'.trans();
# a

say %*ENV<Q>.WHAT;
# Str

say %*ENV<Q>.trans();
# too few arguments passed (1) - 3 params expected

say %*ENV<Q>.trans( [], [] );
# Null PMC access in get_string()

say %*ENV<Q>.trans( [], [] ).WHAT;
# Null PMC access in find_method()

%*ENV<Q> .= trans([ "A" => "B" ], [])'
# Null PMC access in name()

sub foo($s is rw) { $s .= trans( [ 'a' => 'b' ], [] ) }
say foo( 'a' );
# b
say foo( %*ENV<Q> );
# Null PMC access in can()

%*ENV<A> = "OH HAI"; say %*ENV<A>.perl
# ""

%*ENV<A> := "OH HAI"; say %*ENV<A>.perl
# "OH HAI"

%*ENV = {}
# Parrot VM: Can't modify a singleton

%*ENV := {}; say %*ENV.perl
# {}

my %h = %*ENV
# Parrot VM: Can't turn to a singleton type!

%*ENV.keys
%*ENV.values
%*ENV.kv
%*ENV.perl
# No applicable methods.

say %*ENV.elems
# 1

say %*ENV.join
# get_string() not implemented in class 'Env'

In summary:

1. Ordinary strings and strings in %*ENV are unequally treated. You can call
.trans(), or .trans([]) on the former, but you have to send in two non-
invocant arguments to the latter.

2. The result of a successful .trans call on an %*ENV item returns something
which, when touched in any way, causes Rakudo to explode. Most likely a
Parrot
Null value. This is the case regardless of the value of the %*ENV item, and
regardless of whether it has been defined.

3. Actively modifying the %*ENV item using .=trans produces a Null PMC
access
in another Parrot sub, and doing this from within a subroutine, produces
a Null
PMC acces in yet another Parrot sub.

4. Setting an %*ENV item using infix:<=> has no effect. Setting it using
infix:<:=> works. Setting %*ENV itself using infix:<=> produces a Parrot VM
error. Setting it using infix:<:=> works. Assigning %*ENV to another
variable
using infix:<=> produces another Parrot VM error.

5. When calling the methods .keys, .values, .kv or .perl on %*ENV, something
fails with "No applicable methods". (Note, though, that this is
different from
the error message produced by calling a method that doesn't exist on Hash:
"Method 'foo' not found for invocant of class 'Env'") The %*ENV.elems mehtod
always reports '1'. Calling %*ENV.join() produces an error message.

Reply via email to