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

Re: modules and constants

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
December 7, 2019 07:55
Subject:
Re: modules and constants
Message ID:
c7324052-7989-00d4-83ba-8bb7470ff30b@zoho.com
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")

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About