develooper Front page | perl.perl6.users | Postings from December 2019

Re: modules and constants

Thread Previous | Thread Next
ToddAndMargo via perl6-users
December 7, 2019 07:55
Re: modules and constants
Message ID:
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!


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

My keeper on the subject:

Perl6: constraining variable in sub declarations:


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;}



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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About