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

Re: valid values?

Thread Previous | Thread Next
From:
mimosinnet
Date:
April 19, 2019 00:30
Subject:
Re: valid values?
Message ID:
20190419003045.GA6970@mimomedia
El Sunday, 03 de March del 2019 a les 02:09, ToddAndMargo via perl6-users va escriure:

>I want to pass an integer to a sub.  The only
>valid values of the integer are 1, 2, 4, 8, and 16.
>
>Other than using "if" to test their values, is
>there a way to state that an integer can only
>have certain predefined values?

I like this syntax: 

sub MAIN(Int $value where $value ∈ <1 2 4 8 16 >) {
....
}

It is readable and I really like to use the '∈' symbol :D.

Cheers! 

-- 
(≧∇≦) Mimosinnet (Linux User: #463211)

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