New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working with %*ENV in Rakudo is difficult #203
Comments
From johan.viklund@ebc.uu.se$ svn info | grep Revi This works $ ./perl6 -e 'my %t = (); my %s=%t' But this does not $ ./perl6 -e 'my %s=%*ENV' -- |
From @masakHere's a thorough investigation of the strange properties of %*ENV. Rakudo r31926 has an %*ENV variable which claims to be of Hash type, but say 'a'.WHAT; say 'a'.trans(); say %*ENV<Q>.WHAT; say %*ENV<Q>.trans(); say %*ENV<Q>.trans( [], [] ); say %*ENV<Q>.trans( [], [] ).WHAT; %*ENV<Q> .= trans([ "A" => "B" ], [])' sub foo($s is rw) { $s .= trans( [ 'a' => 'b' ], [] ) } %*ENV<A> = "OH HAI"; say %*ENV<A>.perl %*ENV<A> := "OH HAI"; say %*ENV<A>.perl %*ENV = {} %*ENV := {}; say %*ENV.perl my %h = %*ENV %*ENV.keys say %*ENV.elems say %*ENV.join In summary: 1. Ordinary strings and strings in %*ENV are unequally treated. You can call 2. The result of a successful .trans call on an %*ENV item returns something 3. Actively modifying the %*ENV item using .=trans produces a Null PMC 4. Setting an %*ENV item using infix:<=> has no effect. Setting it using 5. When calling the methods .keys, .values, .kv or .perl on %*ENV, something |
The RT System itself - Status changed from 'new' to 'open' |
From @jnthnOn Thu Oct 16 06:31:14 2008, masak wrote:
Jonathan |
From @pmichaudOn Thu Oct 16 06:31:14 2008, masak wrote:
Here's an explanation -- I'll start with the summary first and then look
Rakudo's %*ENV is simply an instance of Parrot's Env PMC. Whenever we In particular, Parrot's String PMC already has a .trans method defined
The .trans method on String PMC doesn't return a value at all -- it does
Since %*ENV returns a Parrot String PMC, and since the .trans method on
The values that come back from %*ENV are String PMCs that aren't tied to However, binding an item using <:=> does activate the set_*_keyed VTABLE
The Env PMC is a singleton PMC that doesn't understand assignment.
You can rebind %*ENV to a different hash, but then it loses its magical
The Parrot Env PMC is a singleton PMC, so apparently there's not a way
Since %*ENV (and the Env PMC) is not really a Hash or Mapping, none of So, with those points out of the way, here are the explanations of the
%*ENV<Q> actually returns a Parrot String PMC, which we've mapped onto
Since the String PMC has its own .trans method, the Str.trans method
This invocation matches the signature for String.trans (not Str.trans),
This ends up calling %*ENV<Q>.trans( ... ), which returns PMCNULL and
Assignment doesn't work, but binding does. Hope this helps -- I'll see which of the above I can clean up. Pm |
From @cspencerThis patch maps %*ENV onto the Mapping interface, allowing the Please let me know if their are any issues to be corrected in it! Thanks, Cory On Tue Nov 11 13:59:46 2008, pmichaud wrote:
|
From @cspencerenv-mapping.patchIndex: src/classes/Mapping.pir
===================================================================
--- src/classes/Mapping.pir (revision 34338)
+++ src/classes/Mapping.pir (working copy)
@@ -34,11 +34,39 @@
=cut
+.sub 'fmt' :method :multi('Env')
+ .param pmc format
+ .param string sep :optional
+ .param int has_sep :opt_flag
+
+ if has_sep goto with_arg
+
+ no_arg:
+ .tailcall self.'!fmt'(format)
+
+ with_arg:
+ .tailcall self.'!fmt'(format,sep)
+.end
+
.sub 'fmt' :method :multi('Hash')
.param pmc format
.param string sep :optional
.param int has_sep :opt_flag
+ if has_sep goto with_arg
+
+ no_arg:
+ .tailcall self.'!fmt'(format)
+
+ with_arg:
+ .tailcall self.'!fmt'(format,sep)
+.end
+
+.sub '!fmt' :method
+ .param pmc format
+ .param string sep :optional
+ .param int has_sep :opt_flag
+
.local pmc it
.local pmc rv
@@ -71,7 +99,15 @@
=cut
+.sub 'iterator' :method :multi('Env')
+ .tailcall self.'!iterator'()
+.end
+
.sub 'iterator' :method :multi('Hash')
+ .tailcall self.'!iterator'()
+.end
+
+.sub '!iterator' :method
.local pmc it
.local pmc rv
@@ -102,7 +138,15 @@
=cut
+.sub 'keys' :method :multi('Env')
+ .tailcall self.'!keys'()
+.end
+
.sub 'keys' :method :multi('Hash')
+ .tailcall self.'!keys'()
+.end
+
+.sub '!keys' :method
.local pmc it
.local pmc rv
@@ -130,7 +174,15 @@
=cut
+.sub 'kv' :method :multi('Env')
+ .tailcall self.'!kv'()
+.end
+
.sub 'kv' :method :multi('Hash')
+ .tailcall self.'!kv'()
+.end
+
+.sub '!kv' :method
.local pmc it
.local pmc rv
@@ -173,7 +225,15 @@
=cut
+.sub 'pairs' :method :multi('Env')
+ .tailcall self.'!pairs'()
+.end
+
.sub 'pairs' :method :multi('Hash')
+ .tailcall self.'!pairs'()
+.end
+
+.sub '!pairs' :method
.tailcall self.'iterator'()
.end
@@ -240,7 +300,15 @@
=cut
+.sub 'values' :method :multi('Env')
+ .tailcall self.'!values'()
+.end
+
.sub 'values' :method :multi('Hash')
+ .tailcall self.'!values'()
+.end
+
+.sub '!values' :method
.local pmc it
.local pmc rv
|
From @pmichaudInstead of duplicating the method calls, a simpler approach might be This might also make it easier for us to create proxies that do Thanks! Pm On Wed, Dec 24, 2008 at 10:19:23AM -0800, Cory Spencer via RT wrote:
|
From @ronaldxsI felt two things were worthy of note at this point. 1) The original example that opened the ticket "my %s = %*ENV" now 2) There is a test for the original example that opened this ticket, as Work, however, remains to be done to make %*ENV more useful as pointed |
From @markjreed
Regular hashes work fine:
Verified present in b51d94. -- |
From @pmichaudNow fixed in 825074a. Thanks! Pm |
@pmichaud - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#57400 (status was 'resolved')
Searchable as RT57400$
The text was updated successfully, but these errors were encountered: