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
One more approach for EXPORT problems. #74
Comments
Turn off containerization for Stash Also added operator (<EXPR>):: which is a shortcut for Stash.new(<EXPR>) Now during import values from Stash are used as-is without deconting. Raku/problem-solving#74
PR rakudo/rakudo#3076 implements this proposal. Passes all tests. No tests for the PR itself are added yet as I'm not certain if this proposal would be accepted. With the above PR the example in gist works as expected if |
The BIG problem with rakudo/rakudo#3081 is that it makes |
@lizmat proposed and implemented with rakudo/rakudo#3081 non-decontainerizing |
Resolves problem described in Raku/problem-solving#74
Resolves problem described in Raku/problem-solving#74
Closed via rakudo/rakudo#3081. |
What Is Wrong
The problem with
EXPORT
is best demonstrated by this example gist where running use.p6 results in:The cause lies in the fact that symbols are exported using
Hash
es which containerize their values. By the momentmod3
is imported there is&trait_mod:<is>
installed inuse.p6
which isScalar
containing the dispatcherSub
, as follows from the error message the output ofBEGIN
block.While I managed to partially address this issue with rakudo/rakudo#3016 but that PR is still more of a palliative but not the cure. After some discussion (though I don't remember exactly where it took place) I was convinced that deconting of
&
-sigiled symbols is not needed and even harmful. An example of why is it so would be:Where
&foo_alias
is actually a writable scalar. Deconting it would break a code in a module consuming code:Proposed solution
Considering that the following use of
EXPORT
routine is now commonplace:and by taking into account that containerization of
Hash
values is done on purpose and is a key part of the language definition, I see the following as a solution with the least need amount of changes to both the core and the user land while improving overall DWIM logic:Stash
behavior changes in a way that assigning to a key doesn't containerize the value. Basically, assignment and binding become the same. I.e.:Stash
has to become the de-facto standard ofEXPORT
return value. I would even make it a warning ifHash
is returned.Because
is somewhat cumbersome, I propose a new operator
( )::
Which follows the common logic of::
used to access symbol tables. Though in this case it'd be used to create one:A sample implementation of the operator can be found in the same gist in file mod3.pm6.
With this proposal there will be no more need to guess if
&foo
is the actual routine or a variable aliasing a routine.Affected Cases
I suspect that a number of 'Cannot invoke this object (REPR: Null; VMNull)' or 'No such method 'CALL-ME' for invocant' issues could be caused the this problem of
EXPORT
. Not necessarily by re-exporting via&EXPORT
but could be indirectly caused by manipulations with aStash
object.The text was updated successfully, but these errors were encountered: