Cannot interpolate trying to emulate EXPORT_OK Tag

Viewed 99

I cannot interpolate ::GLOBAL::EXPORT($var)::. What am I doing wrong?

I'm trying to play with exports because they are hard to optimize sometimes.

I try to produce tags for a group of constants.

In reality a few constants are in visible in module scope, but some of them are in a TAG just to separate them and to use them on demand.

But the objective of my question is just to understand why I cannot interpolate what should seem to be very easy.

The error is an exception with new; I've lost the trace for now.

See the code below.

unit module TestImports;

    sub bar is export  { say "bar sub" }
    sub baz is export { say "baz sub" }
    my $var = 'He heu hey';
    my $aar = 'He heu hey';
    my $vaa = 'He heu hey';
    my $kar = 'He heu hey';
    my $vor = 'He heu hey';
    constant A = 333;
    constant APPART is export(:AP) = 174;

    constant COLOR_A = 24;
    constant COLOR_B = 84;
    constant COLOR_C = 88;
    constant COLOR_D = 92;
    constant COLOR_E is export(:SPECIAL)= 144;
    constant COLOR_F = 98;
    constant COLOR_G = 118;
    constant COLOR_H = 214;
    constant COLOR_I = 800;


    my package EXPORT::MYTAG {
      #filter the colors;
      my %c = TestImports::.grep(*.key.match(/^ ( COLOR_ <[A..Z]>+ ) $ /));
      #filter allready in TAG exported : so we exclude those that we do not want. 
      my %e = EXPORT::.grep(  *.key.grep( none /^ : ( ALL || DEFAULT || MYTAG ) $ /));
      
      #This nearly works but will fail for :SPECIAL Tag because it's yet exported :(
        for %c {
            next if .key eq 'EXPORT';
            .key.say;
            OUR::{.key} := .value;    
        }
        #NOTE: So we must exclude, :SPECIAL (and ev. others) building a loop with e.
        #IF i did well red the doc ALL SPECIAL should be in GLOBAL::EXPORT::SPECIAL::%(kv);
        #and 
        ::GLOBAL::EXPORT::SPECIAL::.raku.say => WORKS; ==> (COLOR_E(80)) SO: 
        for %e.kv -> $k,$v {
            #HERE IS THE QUESTION!!!!!!
            ::GLOBAL::EXPORT::($k)::.raku.say; #SHOULD WORK but does not: WHY.
        }
        
      }

Main script just for testing is this one.

#!/bin/env raku
use TestImports :DEFAULT, :MYTAG :AP ;

#Most of the time : Everything works!but it should work always
say TOTITOTO;
say INTER;
say WANDER;
say WANDER_FULL;
say WANDER3FULL;
say APPART;
say TestImports::A;

#say COLOR_INTER;
bar();
baz();

Thing.new.foo;
1 Answers

This answer is barely an answer, but then your question is barely a question, so perhaps it all balances out. ;)

Cannot interpolate trying to emulate EXPORT_OK Tag

I googled "EXPORT_OK". It's Perl. Simple forms of it seem simple. Why aren't you just sticking with simple tagging?

I cannot interpolate ::GLOBAL::EXPORT($var)::

There's no such package as GLOBAL::EXPORT. The EXPORT generated by Rakudo is a lexical package (declared with my) not a global package (declared with our). Your EXPORT::MYTAG package is explicitly declared with my.

::GLOBAL::EXPORT($var) attempts to call a package as if it were a function which won't work either. But that's presumably just a typo.

At a guess you meant EXPORT::($var) or something like that.

I don't know what you really want because your code doesn't compile and is too long and messy.

I'm trying to play with exports because they are hard to optimize sometimes.

If you mean Perl exports, Raku isn't Perl.

If you mean Raku exports, and mean performance, then please share your --profile results. If you mean some other aspect of optimizing, then please clarify what that is.

In reality a few constants are in visible in module scope, but some of them, are in a TAG just to separate them and to use them on demand.

The constant declarator has an implicit our declarator by default. If you don't want that, put my in front, i.e. my constant ....

But the objective of my question is just to understand wy i cannot interpolate what should seam to be very easy.

If the above hasn't answered your question, please produce a much shorter and cleaner version of your question and then we might be able to help.

The error is an exception with new, i'v lost the trace for now.

The error I see in your deleted "answer" is:

Failure.new(exception => X::NoSuchSymbol.new(symbol => "GLOBAL::EXPORT::SPECIAL"))

That's a Failure value (which is an error value containing an unthrown exception that allows code to continue to run provided nothing tries to use the error value as if it were OK).

It says there's no such symbol (NoSuchSymbol) as GLOBAL::EXPORT::SPECIAL. That's correct, because there is no such symbol/package, as explained near the start of this answer.


I see this in your comments under your deleted "answer":

I think the example is too long

Yes. I'm pretty sure that, whatever it is that you're trying to ask, it should be askable in less than 10 lines of code. See Minimal Reproducible Example for further guidance on how best to ask a question.

But I suspect the primary problem is more basic than that.

If you are experiencing problems with Raku exporting, then it seems likely that you're just using it incorrectly.

If you are using it correctly, then the first thing to do, before thinking about trying to optimize anything, is to use --profile in accord with Knuth's dictum that "Premature optimization is the root of all evil" and share your results.

Related