On 2019-12-05 23:39, ToddAndMargo via perl6-users wrote:
Hi All,

Its there a way, if you import a module that is also
imports a bunch of constants into your main program
to be used globally?

If so, what is the syntax in the module and in the main program?

And what happends if there is a name conflict between
the module and main program?

Many thanks,
-T


Follow up:

With the help of Holli over on Stack Overflow,
I came up with a way I really like.

Thank you all for the tips!

-T

`anonymous constraint` is a bit obscure language,
but ...


My keeper on the subject:


Perl6: constraining variable in sub declarations:

References:

https://stackoverflow.com/questions/59222421/perl6-raku-how-to-i-restrict-the-values-allowed-in-a-variable
    https://docs.raku.org/type/Signature#index-entry-where_clause


Note: the `where clause` not confined to just subs.

Example format:
   sub foo( Int $binary where * ~~ 0|1 ) { ... }


Sample sub:

    sub abc( Str $x where * ~~ "abc" | "def" ) {say $x;}

    abc("abc")
    abc

    abc("def")
    def

    abc("hij")
    Constraint type check failed in binding to parameter '$x';
    expected anonymous constraint to be met but got Str ("hij")

Reply via email to